-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
The thread functions defined in common-thread-private.h give a platform agnostic thread and mutex API.
On Windows, bson_thread_create wraps CreateThread. This creates a new thread handle. And bson_thread_join wraps WaitForSingleObject to wait on that thread handle, but it does not close the thread handle after waiting.
The documentation for CreateThread states:
> The thread object remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle.
The leak can be observed this with a simple example program that just creates and destroys a mongoc_client_pool_t repeatedly (which creates one monitoring thread and joins it repeatedly). The example is attached as handle-leak.c. A screenshot of process explorer showing a large number of open handles is also attached.