-
Notifications
You must be signed in to change notification settings - Fork 295
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
Azure SQL: System.ObjectDisposedException: Cannot access a disposed object on OpenAsync #449
Comments
This does seem to be related to #359 |
@cheenamalhotra It seems like a different issue for me. #359 was caused by socked disposed by reconnect code not waiting for the OpenAsync to complete and hitting the old (disposed) socket. Stack traces looks similar because of CheckPoolBlockingPeriod. The real stack trace is
and it is not the same as in #359:
|
@cheenamalhotra I was able to reproduce it. Here is a sample code: https://github.com/PashaPash/ConnectRace/blob/master/ConnectRace/Program.cs It is basically SNITCPHandle.Connect with few Thread.Sleep added to get an exact execution order. Conditions seems to be Connect Timeout < real host response timeout + bad luck on simultaneous Dispose / Connect calls. |
Thanks @PashaPash I will give it a try soon! |
Hello! We faced a very similar problem a few days ago. Stack trace:
Environment: |
Any news on this? Recently encountered this on EF Core 3.1.7 |
I seem to be having this issue as well. It only happens when running my code from AKS (on linux machines), when doing the exact same thing locally from Visual Studio, no problems. I get the error about once per minute. (It's running in a background task, that's pretty much continuously running)
Using Microsoft.EntityFrameworkCore.SqlServer 3.1.11, and connecting to an Azure SQL Server. |
Hi @RCTycooner We received update on another thread regarding issues in AKS environments ( #647 (comment)), could you check with Azure Support if this is related to your case too? As I see socket exceptions in your stacktrace, that may be pointing to same issue. |
@PashaPash I am closing this issue assuming it was solved regarding the last comment and inactivity. Feel free to reopen or create a new issue. |
@JRahnama we are still running into this in version 5.1.5 We have no clear reproduction scenario. We have an application serving hundreds of customers. Each customer has their own database. Every few weeks the connection to 1 specific (but random each time) database becomes broken with the following stacktrace: stacktraceException opening following connection: 'xxx' 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)", "exceptionDetails": [ { "message": "Cannot access a disposed object.\nObject name: 'System.Net.Sockets.Socket'.", "type": "System.ObjectDisposedException", "raw": "System.ObjectDisposedException: Cannot access a disposed object.\nObject name: 'System.Net.Sockets.Socket'.\n at Microsoft.Data.SqlClient.SNI.SNITCPHandle..ctor(String serverName, Int32 port, Int64 timerExpire, Boolean parallel, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo, Boolean tlsFirst, String hostNameInCertificate, String serverCertificateFilename)", "stack_frames": [ { "function": "Microsoft.Data.SqlClient.SNI.SNITCPHandle..ctor(string serverName, int port, long timerExpire, bool parallel, SqlConnectionIPAddressPreference ipPreference, string cachedFQDN, ref SQLDNSInfo pendingDNSInfo, bool tlsFirst, string hostNameInCertificate, string serverCertificateFilename)" } ] }, { "message": "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)", "type": "Microsoft.Data.SqlClient.SqlException", "raw": "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)\n ---> System.ObjectDisposedException: Cannot access a disposed object.\nObject name: 'System.Net.Sockets.Socket'.\n at Microsoft.Data.SqlClient.SNI.SNITCPHandle..ctor(String serverName, Int32 port, Int64 timerExpire, Boolean parallel, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo, Boolean tlsFirst, String hostNameInCertificate, String serverCertificateFilename)\n at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\n at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnectionString connectionOptions, Boolean withFailover)\n at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)\n at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)\n at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool)\n at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)\n at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)\n at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)\n at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)\n at Microsoft.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen()\n--- End of stack trace from previous location ---\nIn our case the situation resolves itself by clearing some internal caching (unrelated to sql) which causes a burst of queries to all tenants, which (we think?) causes the issue to stop happening for a while Edit; I now see there is a 5.2 version, which contains some fixes that might be related (for instance: #1029) We're going to update and see if the issue goes away edit2: now we found #2378 I guess we'll wait for this to be fixed before updating |
Describe the bug
On Azure SQL, after short server unavailability / failover, subsequent call to OpenAsync fails with
System.ObjectDisposedException: Cannot access a disposed object.
Stack trace:
Exception is re-thrown with
throw e
atCheckPoolBlockingPeriod
for Azure SQL connections, so only two first lines seems to be related.MultiSubnetFailover
attribute is not set, so it probably follows non-parallel connect path.To reproduce
Synthetic repo (based on SNITCPHandle.Connect code +Thread.Sleep to force exact timing): https://github.com/PashaPash/ConnectRace/blob/master/ConnectRace/Program.cs
Unable to clearly reproduce it without manual Thread.Sleeps - seems to happen on Azure only, and during (or immediately after) Azure SQL downtime.
Expected behavior
OpenAsync either fails with real network-related error or connects successfully.
Further technical details
Microsoft.Data.SqlClient version: 1.1.1, with #359 fix applied
.NET target: Core 3.0.3
SQL Server version: Azure SQL, listed as 12.0.2000.8 in SSMS
Operating system: Docker Image mcr.microsoft.com/dotnet/core/aspnet:3.0, running on AKS
Same stack trace reported by @TheDruidsKeeper: #359 (comment)
The text was updated successfully, but these errors were encountered: