Microsoft KB Archive/259753

= FIX: Deadlock in OLE DB Session Pooling in an STA COM Object =

Article ID: 259753

Article Last Modified on 4/7/2006

-

APPLIES TO

 Microsoft OLE DB 2.1, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 2000 Standard Edition  Microsoft OLE DB 2.5, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 2000 Standard Edition</li></ul> </li> Microsoft OLE DB 2.6, when used with:  Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 2000 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q259753

<div class="symptoms_section">

SYMPTOMS
When you use OLE DB session pooling from a single threaded apartment (STA) COM object on a Windows NT 4.0 computer, STA COM object method re-entrancy may cause a deadlock in the OLE DB synchronization code.

<div class="resolution_section">

RESOLUTION
To resolve this problem, obtain the latest service pack for Microsoft Data Access Components 2.6. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

300635 INFO: How to Obtain the Latest MDAC 2.6 Service Pack

Hotfix
The English version of this fix should have the following file attributes or later:

<pre class="fixed_text">  Date         Time    Version       Size      File name     Platform ---  12/06/2000   19:41   2.60.7006.0   459,024   Oledb32.dll   x86 This fix does not contain a Hotfix.exe installer. A Readme.txt file is included which details the installation procedure. This fix should not require a restart in order to be installed.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Data Access Components 2.6 Service Pack 1 and MDAC 2.7.

<div class="moreinformation_section">

MORE INFORMATION
Method calls to an STA COM object can be re-entered on the same thread, in much the same way as a recursive function call (where the same thread of execution can re-enter the same function). For example, if you peek at the Windows message loop by using the Win32 API call PeekMessage inside an STA COM object method, this can cause a second pending method call to re-enter the same STA COM object method on the same thread of execution. This is the design of STA COM objects and is not a bug. Under normal circumstances, this does not cause a deadlock, and both method calls execute normally.

In this specific case, the OLE DB code internally calls the Win32 API function CoCreateInstance to instantiate an internally used COM object. In certain circumstances, this can trigger STA COM object method call re-entrancy on Windows NT 4.0. In this particular case, a deadlock occurs in the OLE DB code because OLE DB obtains an internal lock while processing the first method call and then triggers STA re-entrancy while this lock is held. The original lock held by the first method call blocks the same thread inside of the second method call from obtaining another dependent lock in the OLE DB code. Because the first lock is held by the same thread, this lock will never be released, and this blocks other threads in the same process from using OLE DB.

The occurrence of this deadlock is rare because it requires a specific series of events to occur at precisely the same time. To determine if this specific problem has occurred, attach a debugger to the process and look for a call stack that enters some COM method X, then enters OLE DB code, then re-enters the same method X further up the stack, and then goes back into OLE DB code. The top of the stack of the deadlocked thread will contain the following function calls:

<pre class="fixed_text">ntdll!NtDelayExecution+0xb KERNEL32!SleepEx+0x34 KERNEL32!Sleep+0xb OLE DB32!TCMHashTableLocked<unsigned short const *,CUdlCacheValue *>__ReaderLock+0x85