SqlClient: Errors after upgrading to 5.2.0 from 5.1.5 on Linux
After upgrading 5.1.5 to 5.2.0 on Linux (Ubuntu) .NET 8 I’m getting thousands of errors:
Exception message:
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught)
---> System.TimeoutException: The socket couldn't connect during the expected 14965 remaining time.
Stack trace:
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught)
---> System.TimeoutException: The socket couldn't connect during the expected 14965 remaining time.
at Microsoft.Data.SqlClient.SNI.SNITCPHandle.Connect(String serverName, Int32 port, TimeoutTimer timeout, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo)
at Microsoft.Data.SqlClient.SNI.SNITCPHandle..ctor(String serverName, Int32 port, TimeoutTimer timeout, Boolean parallel, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo, Boolean tlsFirst, String hostNameInCertificate, String serverCertificateFilename)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open()
Some requests work fine, but about 50% throw this error. Reverting back to 5.1.5 solves the problem.
Further technical details
Microsoft.Data.SqlClient version: 5.2 .NET target: NET 8 SQL Server version: SQL 2017 on Linux Operating system: Ubuntu 22
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 15
- Comments: 83 (37 by maintainers)
Hotfix v5.2.2 is released.
NOT FIXED attn @JRahnama
The issue is not fixed in 5.2.1
I’m getting the same error under high load:
Reverting to 5.1.5 fixes the issue
@BlythMeister Yes, 5.1.6 is being worked on
I integrated the package provided by @JRahnama and run the load tests. It seems to fix the issue, thanks for that!
Here the numbers to compare against:
Please note the numbers do not imply a certain quality of the fix, the load test runs aren’t deterministic. Important for me is that we keep the expected thresholds and that there are no failures. It feels the fix is slightly slower, but only a benchmark would reveal that.
The provided workarounds aren’t mitigating the issue completely in our case. The only “solution” is actually to downgrade to 5.1.5
We’re load testing our service with k6 using the ramping-vus executor. We’re ramping it up to 1000 vus and let the test run for 3min. For one of our scenario we tested using different connection timeouts with the 5.2.1 version as suggested workaround 1)
The higher we put the timeout the better it went. Going to 180s we got zero errors, but we started to get client timeouts. Which is not acceptable as well.
The suggested workaround 2) to increase the Threadpool minimum size did not provide any better results. Honestly, we didn’t try out the suggested workaround 3) as it sounds just too scary…
So please a proper fix would be really appreciated. Is there in the meantime an ETA for the fix?
@JRahnama hmmm okay okay… maybe switch to Chat GPT instead of Bing AI 😉
Here’s what it suggested when I prompted “An annoyed customer responded with this. Please help me craft a short responses.”
You see, a high-quality GPT response like that gives you the impression that you aren’t being passive-aggressive. And it almost gives the impression that you care about the problems you have caused for your customers.
I can confirm that this is indeed broken in 5.2.1 as well, and actually worse than 5.2.0. This is trivial to reproduce, basically do exactly what @alex-jitbit – just open a bunch of connections to simulate what a real application experiencing traffic would do.
In 5.2.0, SqlClient crashes immediately with that same. When we use 5.2.1, there seems to be some kind of timeout mechanism that makes the cashes take forever, and effectively freezes up the whole application.
Stack trace seems to be the same:
@alex-jitbit if increasing the ConnectTimeout is not a preferred solution, I may have a solution for this issue until SqlClientX is out for good. Give me some time to test my proposed solution and discuss that internally with other team members, in case of positive outcome I will give you another nuget to test with.
@JRahnama I’m sorry to be so negative here, but your responses are completely inadequate and totally unacceptable. They demonstrate a lack of empathy and acknowledgement of the problems your team has caused.
You need to keep in mind that Microsoft’s customers pay a preposterous amount of money for SQL Server and your team’s untested changes have made it effectively unusable in Linux. I really can’t tell if your team doesn’t understand this… or they simply don’t care.
If Microsoft’s plan is for us to stop using SQL Server – which would make sense, when they can charge the same amount of money to host a database that someone else maintains for free – then just please just say so. While that’s a lot of work for us, at least PostgreSQL’s team of volunteer contributors demonstrates more more professionalism that your team has been.
Otherwise, at the very least, please run your replies through Bing AI to at least feign some kind of empathy and learn what key points you need to say when responding to a showstopper bug from your customers.
This issue should be pinned.
There are a couple of PRs to be bacported to 5.2 and the we will proceed with the release of hotfix 5.2.2
Here are benchmarks after the fix:
BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.4037/23H2/2023Update/SunValley3) 13th Gen Intel Core i7-1365U, 1 CPU, 12 logical and 10 physical cores .NET SDK 8.0.400 [Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2 .NET 8.0 : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0
below are results from 5.1.5::
BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.4037/23H2/2023Update/SunValley3) 13th Gen Intel Core i7-1365U, 1 CPU, 12 logical and 10 physical cores .NET SDK 8.0.400 [Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2 .NET 8.0 : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Job=.NET 8.0 Runtime=.NET 8.0
My sample app was the repro provided from this issue with ConnectTimeout set to 10 seconds.
Is there scope to create a 5.1.6 which is 5.1.5 with the dependencies on Azure.Identity and Microsoft.Identity.Client updated to patches with CVE-2024-35255 fixes applied. I fully understand find a “proper” solution may take time, but forcing users connecting to SQL server and running on linux into unproven workarounds on PRD systems to be able to patch against such a serious vulnerability in another Microsoft library is completely unacceptable.
A patch of 5.1.5 which updates the transient dependencies with vulnerabilities is (in my opinion) essential. It is now nearly 2 months since these transient dependencies were updated to fix the CVE, but it’s impossible to get these updates.
In my testing with 50 concurrent connections, I did not notice any specific performance issues. This is based on observation rather than benchmark testing. It worked pretty well when I increased the timeout to 60 seconds. This provided enough time for the socket to connect. I think that would be the optimal workaround for now. However, as I mentioned before, give me some time to test my findings, and I will get back to you.
So I’m trying to find the most suitable workaround for our application that works properly in production.
am I to understand that if I increase the connect timeout parameter the issue does not occur? Will it then still take a lot of time to connect each time. Or does it only take a lot of time until enough threads are created to handle all connections, and will it then be fast until the application is restarted?
I also don’t really understand the resistance of setting min threads. If apparently your application needs that amount of threads in production workloads, what is the issue in setting it so it starts with enough threads?
Nb: let’s please try to keep this discussion productive. I too would like to stress this is a pressing issue for us, but let’s not make this a toxic discussion
that was an oversight. We will investigate the issue and will get back here.
@JRahnama just tested with the exact repro I provided, same error on 40 concurrent connections.
@ABAG603 Fix is merged in the main branch by PR #2395. Hotfix release v5.2.1 is planned, but date yet TBD.
Closing the issue as fix is merged and will be available by next hotfix release.
5.1.x will be released soon ( in a week or so) with updated dependencies.
@cbi-at-varian Great work showing what we are experiencing
Oh wow, surely the “stable” flag should be removed then?
We’ve not updated to 5.2.x yet but we’re running Linux clients to Windows MS SQL.
Is everyone just waiting in the hope there’s a 5.1.x release that has the updated dependencies?
you can have a look at the broader picture in this discussion.
@saurabh500 the measurements are on the client side of the load tests. Those numbers therefore include the web stack, some small business logic including accessing the database.
Could someone please test the package below to see if the issue is resolved? Simply change the extension to
nupkg. Note that this is an unsigned package and is intended for testing purposes only. Microsoft.Data.SqlClient.6.0.0-pull.122701.zipUpdate: Our test pipelines passed with the changes, and the provided repro is working well with this set of modifications. The fix appears promising. I’ll wait for the impacted users’ test results before proceeding with the PR. Also I will look into adding some tests if possible to prevent this from happening in future. Thank you all for your patience. Also thanks to @David-Engel for pointing out the root cause and solution.
@JRahnama Whilst i fully appreciate your working on a proper fix for this issue. Is there really no scope to release a hotfix to 5.1.5 with the dependencies updated as per my comment - https://github.com/dotnet/SqlClient/issues/2378#issuecomment-2247689996 ??
@apxltd Thank you for your feedback. We appreciate you taking the time to share your concerns with us.
We are seeing this issue in production as well, although it seems pretty random when it occurs. We use Entity Framework Extensions and notice calls from that library seem to run into it more. We are pretty stuck here since we upgraded to dotnet8 and this started happening, would love to see this fixed.
Dotnet8 on chiseled ubuntu images with 5.2.1 sqlclient
Because of this issue, staying on version 5.1.5 also prevents you from automatically receiving vulnerability fixes for
Azure.IdentityandMicrosoft.Identity.Clientavailable in the later versions ofMicrosoft.Data.SqlClient.@JRahnama repro here: https://gist.github.com/alex-jitbit/1eca9a1f014e036691bdc35cd852c726 the bug is even reproducable when running on Windows under WSL2 however the error is slightly different in that case (see repro description)
@JRahnama any update on a release date for 5.2.1 yet? It’s been a couple of weeks now and still no hotfix
Some obervation from me hoping it helps investigation:
We started getting this problem in alpine for a test that starts multiple threads connecting some same database in parallel. Other tests work fine. Our connection strings do not specify instance or port. Tried adding some delays in the code inside the different tasks to affect timing and then we got a different error instead of the one mentioned in this ticket:
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. 12:25:02 at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
Here’s how threads are created in the test: var tasks = schedulers.Select(s => new TaskFactory().StartNew(s.Start)).ToList(); foreach (var t in tasks) t.Wait();
Reverting back to v5.1.5 fixed this, so we are not updating to v5.2.0 until we know more.
If you are on Linux/macOS and specify both port and instance name in the connection string (like server,12345\instance), that might be the source issue. There appears to have been a regression in 5.2.0 on non-Windows where it isn’t ignoring the instance name when both it and the port are specified.
I had the same problem, I downgrade to 5.1.5 and it worked again
SQL 2019 - Windows Server - .NET 8