Forum Discussion

Pedro-Goncalves's avatar
Pedro-Goncalves
Copper Contributor
Aug 30, 2023

"Thread was interrupted from a waiting state" from DbConnectionPool.CleanupCallback

Hi,

 

I'm getting this error, and I'm not able to fix it, or even understand from where it comes.

I'm also sure that all my SqlConnection are instanciated with Using (VB.NET), so the Dispose should be called for every one.

 

Does anyone have an idea about the cause?

This error started after upgraded the app to the .NET Framework 4.8.1, from 4.6.2. Maybe it's a coincidence...

 

Source: mscorlib; Message: Thread was interrupted from a waiting state.; Data:; StackTrace:    at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)

   at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)

   at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)

   at System.Data.ProviderBase.DbConnectionPool.CleanupCallback(Object state)

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

   at System.Threading.TimerQueueTimer.CallCallback()

   at System.Threading.TimerQueueTimer.Fire()

   at System.Threading.TimerQueue.FireNextTimers();

 

Regards,

Pedro

2 Replies

  • Hi Pedro-Goncalves,
    Thanks for posting your issue here.
    Here is the solution of your problems:

    https://stackoverflow.com/questions/35979245/vb-net-does-sqlconnection-get-closed-automatically-in-a-try-catch-if-exception-i

    let me know if you have any query on this.
    Best Regards,
    AddWebSolution

    • Pedro-Goncalves's avatar
      Pedro-Goncalves
      Copper Contributor

      Hi AddWebSolution,

       

      Thank you for your reply, but I'm aware of the need to close every DbConnection. The issue was that I just couldn't find in my app where I would be opening a connection without a proper close or dispose of it.

       

      Meanwhile I’ve decompiled the System.Data.dll, to check the code of the CleanupCallback() function, and find out that the code line where it is raising the exception is the one calling WaitOne() function, and that means that in fact it is the thread that is running the function that is interrupted.

       

      So, I conclude from this that must be some other process, clearly outside my application, that is doing that, probably due to external factors or low-level issues in the operating system or .NET Framework itself and hasn’t nothing to do with connections not closed.

       

      In this context, the CleanupCallback() function is a method of the System.Data.ProviderBase.DbConnectionPool class, that it is typically called by the connection pool's internal management mechanism.

       

      Given this context, the "Thread was interrupted from a waiting state" exception that occurs within the CleanupCallback() function is likely associated with the thread that is responsible for managing the connection pool, and not with individual connections that are being opened and closed by the application.

       

      The thread interruption seems to be occurring within the internals of the ADO.NET connection pool management, probably due to factors outside the control of the application, such as system-level issues or low-level thread management by the .NET Framework itself.

       

      So, what can it be? How can I investigate the system environment for potential external factors or specific configurations that could be affecting the behavior of the thread pool and connection pool management?

       

      Regards,
      Pedro

Resources