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

Thread pool task executor can cause memory leak when handling exhaust command.

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.0-rc0, 6.0.7, 7.0.0-rc3
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • v7.0, v6.0
    • Service Arch 2023-05-15, Service Arch 2023-05-29, Service Arch 2023-06-12
    • 0

      Thread pool task executor when it handles exhaust commands can leak resources. We noticed the leakage with SingleServerDiscoveryMonitor which is the only consumer at this moment which uses thread pool task executor to schedule exhaust commands . Below is the racy sequence with exhaust command workflow.
       
      1.  Thread 1: Starts processing the streamable hello cmd response  and runs line 842, and returns true (i.e, cbState is neither canceled nor finished at this point);  and the thread pauses.

      2. Thread 2: Cancels the exhaust command which will cancel the cbState and  resets the callback in cbstate  to release any  resources the callback is holding.

      3. Thread 1: Thread resumes, then acquires the executor mutex lock and sets the callback in  cbState   back to the original callback function. And, this can cause memory leak.

      In the BF, we were ending up with indirect leak due to this circular reference:  SingleServerDiscoveryMonitor holds a reference to TaskExecutor::CallbackHandle and which in-turn holds a reference to ThreadPoolTaskExecutor::CallbackState  and that contains CallbackFn which holds a reference to SingleServerDiscoveryMonitor.

            Assignee:
            jason.chan@mongodb.com Jason Chan
            Reporter:
            suganthi.mani@mongodb.com Suganthi Mani
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: