Microsoft KB Archive/902197

= The second call may fail with an &quot;ERROR_INVALID_HANDLE&quot; error when two threads call the RegOpenKeyEx function in Windows =

Article ID: 902197

Article Last Modified on 7/8/2005

-

APPLIES TO


 * Microsoft Windows Server 2003, Standard Edition
 * Microsoft Windows Server 2003, Enterprise Edition
 * Microsoft Windows Server 2003, Web Edition
 * Microsoft Windows XP Professional
 * Microsoft Windows XP Home Edition
 * Microsoft Windows XP Media Center Edition 2002
 * Microsoft Windows XP Tablet PC Edition
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows NT Server 4.0 Standard Edition
 * Microsoft Windows NT Advanced Server 4.0
 * Microsoft Windows NT Workstation 4.0 Developer Edition

-





SYMPTOMS
Consider the following scenario: One thread calls the RegOpenKeyEx function to open a predefined key. Another thread calls the RegOpenKeyEx function to open a key that is located under this predefined key. However, the second call may fail with the following error:

ERROR_INVALID_HANDLE

For example, if the following threads call the RegOpenKeyEx function at the same time, the call to the RegOpenKeyEx function in Thread 2 may fail:
 * Thread 1: Calls RegOpenKeyEx (HKEY_LOCAL_MACHINE, NULL, ..., &hkey)
 * Thread 2: Calls RegOpenKeyEx (HKEY_LOCAL_MACHINE, L&quot;SOFTWARE\\Microsoft&quot;, ..., &hkey)

Note This error does not occur across process boundaries.



CAUSE
This problem occurs because the RegOpenKeyEx function experiences a race condition that is related to predefined keys.

For example, assume that the hkey parameter is a predefined key. Also assume that an lpSubKey parameter is NULL, or an empty string. In this scenario, the handle of the predefined key is closed one time and is then reopened in the context of the caller. When the handle of the predefined key is closed, the RegOpenKeyEx function that another thread calls may fail with the error that described in the &quot;Symptoms&quot; section.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
This problem also occurs on uniprocessor systems.

Keywords: kbtshoot kberrmsg kbbug KB902197

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.