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
Hang with SQLClient close connection #886
Comments
Driver version? |
Hi @hungdqht Could you explain more about under what circumstances does this occur? |
Hi @cheenamalhotra , |
|
Hi @hungdqht #755 was fixed in v2.1.0, however System.Data.SqlClient is not receiving Bug Fixes. |
unfortunately we ccan't reproduce the problem with load test. However we noticed that the problem happend when we upgrade the server from 2012 to 2016. The avg cpu is higher on 2016. We moved it back to 2012 and continue to monitor the servers. I will update if it happen again. Thank you |
Hi @cheenamalhotra , I Study the code and the dump file and it looks like the thread deadlock with itself at the code below protected override object ObtainAdditionalLocksForClose() { When close the connection thread try to obtain the _parserLock which it already have it. Look into the class SqlInternalConnectionTds I found this comments confirmed that deadlock issue So I think the thread somehow take _parserLock and not/fail to update ThreadHasParserLockForClose to true and when it close the connection it deadlock with itself. I search the usages of the _parserLock.Wait methods and see that it used several places and some of them set the ThreadHasParserLockForClose to true when it has _parserLock but not all. I wonder if we must set ThreadHasParserLockForClose to true when we have _parserLock why we don't do that in _parserLock.Wait method internal void Wait(bool canReleaseFromAnyThread) also this method is not release the lock on semaphore. It not call Monitor.Exit in every cases but always Enter. The problem still happen under heavy load and we still stuck at finding a solution |
That's interesting. We will take a closer look and get back to you! |
@hungdqht Do you have any news ? Your hang is still present ? I had exactly the same problem. My app is on Net Core 3.1 with Entity Framework 6. Hangs happened sometimes in IIS in production and 70-80% of the threads are waiting here : " Microsoft.Data.SqlClient.dll!Microsoft.Data.SqlClient.SqlInternalConnectionTds.SyncAsyncLock.Wait(bool canReleaseFromAnyThread = false)" I had the problem with System.Data.SQLClient 4.7.0 so i upgrade to Microsoft.Data.SqlClient with ErikEJ.EntityFramework.SqlServer but the problem is still here. In ErikEJ.EntityFramework.SqlServer, Microsoft.Data.SqlClient version is 2.1.4. Maybe i can try to update to 4.1 and test ? |
@crydante yes just add an explicit reference to 4.1 |
My hang is resolved with upgrading Microsoft.Data.SqlClient to 4.1 AND disable MARS for all SqlConnections |
We sometime experienced the application hang on IIS, 60% of the threads has the same stack as below and all of them seems stuck when trying to release the connection to the pool. After restart the w3wp process it is back to normal.
We use System.Data.SqlClient 4.8.4121
Could you please check if this is a bug and how we can avoid that happen? Thanks in advance
The text was updated successfully, but these errors were encountered: