Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3634

Windows thread handles are leaked

      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.

        1. handle-leak.c
          0.8 kB
        2. handle-leak.png
          handle-leak.png
          28 kB

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: