Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-53477

ThreadPool::waitForIdle should be interruptible on thread pool shutdown()

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.9.0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • ALL
    • Service Arch 2021-02-22, Service Arch 2021-03-08, Service Arch 2021-03-22
    • 131
    • 2

      The header file claims that it is legal to call waitForIdle before shutdown is called. But it is not. On shutdown, the thread pool will drain all pending tasks and shut down all threads, after which the _numIdleThreads will become 0. So if we call shutdown, then waitForIdle would hang because _numIdleThreads (0) would be < the size of _thread (until join is called where we finally clear the _threads).

      To fix this, we can make waitForIdle return on shutdown. As the comment in the thread pool header file says, if it is called before shutdown() is called, there is no guarantee that there will still be no pending tasks when the function returns. Or we should fix the comment.

       

      Acceptance criteria:

      Write unit test to verify reported behavior. If a hang is observed then figure out if we want to notify the condition variable/fix the hang. 

            Assignee:
            george.wangensteen@mongodb.com George Wangensteen
            Reporter:
            lingzhi.deng@mongodb.com Lingzhi Deng
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: