-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlConnection fails to reliably keep long-running connection open #25458
Comments
We're facing some horrendous internal debates here based on how to work around this not being fixed. We've known about it for ages and ages. https://stackoverflow.com/questions/16347389/sqlserver-wedged-connection-due-to-network-drop |
@saurabh500 @corivera isn't this fixed in 2.2? The KeepAlive flag was added and we're using in Azure Data Studio with latest bits... correct? |
@kevcunnane : The diff of unmerged dotnet/corefx#33024 says definitely not fixed yet. |
This is not fixed in 2.2 and the PR for master is undergoing discussions about the unit of the API. For 2.2 the fix depends on networking APIs as well. |
@jhudsoncedaron have you had a chance to use the OS keepalive settings to alleviate this problem? |
@saurabh500 : There is no OS setting that I know of to turn on keepalive for all sockets. |
@wfurt mentioned settings for macOS on the thread at https://github.com/dotnet/corefx/issues/32894#issuecomment-431189315 For Linux, http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html could help |
The recommended setting for Sql clients is mentioned at @jhudsoncedaron , you are facing this issue on Linux/macOS. Is that right? |
@saurabh500 : I don't need to set precise timeout values. I just need to turn keepalive on at all to keep threads from getting stuck forever inside SqlDataReader.Read(). Right now it doesn't matter what the OS is. While there's OS specific settings to tune the values, the SetSocketOption call needs to execute to turn it on per socket. |
I don't think I follow. Based on the context of this issue, I understood that when you are trying to re-use a connection, after long idle period, the connection is failing. |
@saurabh500 : I did a version hunt. It was restored to working again on Windows by turning off SNI globally. dotnet/corefx@23709d0 |
What about it? The diff you have mentioned here, turns off Managed SNI on Windows, which means that the SNI (SQL Network Interface) implementation written in C++, is being used on Windows. |
@saurabh500 : This discussion is probably going to get degenerate. From our perspective, Managed SNI has switched on and off a few times and the bug comes and goes and we're using hardware workarounds and most of the time the thread that does get stuck isn't holding any locks. We're not willing to attempt to support environments w/o the hardware workarounds until the bug is really fixed. The code comments say Managed SNI is coming back again. |
I can assure you that Managed SNI has not been turned on, on any released version of SqlClient, for Windows. It was turned on, in one of the preview releases and then turned off. |
@saurabh500 : We used preview releases of stuff. |
There are lot of bug fixes after 2.0 preview releases and I do recommend upgrading to a newer released version of SqlClient. |
@jhudsoncedaron Can you tell me your version of SqlClient as well? There are 4.6.0-preview on nuget, which have a lot of bug fixes in them. |
The current version is 4.5.1 release. We've been on preview versions of SqlClient in the past after discovering that cross-versioned binaries normally work really badly and there's a critical fix only available in a preview release for something in .NET MVC so we move the entire framework as a unit. |
This issue affects applications such as SQL Operations Studio which have long-running connections (e.g. backing a T-SQL Editor) based on the .Net Core stack. On the .Net Full stack, the connection reliably stays open or reports as non-open in the ConnectionState, allowing the application to reopen as needed. However on the .Net Core stack the state is shown as Open but on attempting any command the command will attempt to run for ~60sec, then fail with an error message
This has a high impact on reliability of tools build on top of .Net Core for SqlClient usage.
Related issue: microsoft/azuredatastudio#870.
**Diagnosis by @saurabh500 **:
Windows impl of SqlClient sets some Keepalive values which Unix stack doesn’t
SqlClient should set the keep alive values.
Original issue details:
Steps to Reproduce:
Expected:
Actual:
Note that we're actually checking if the connection isn't open but this isn't reliable when it comes to TCP sockets closing. This may well be a driver-side issue, but any fix/workaround we can apply would be good.
Here's our code to close & reopen on issues:
We can add connection.Close() in this case which might fix issues where connection is in a broken state, but definitely doesn't fix the error all up.
The text was updated successfully, but these errors were encountered: