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

Memory leak in TransactionCoordinator associated to long-lived cancellation source

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 8.1.0-rc0, 8.0.0, 8.2.0-rc0
    • Component/s: None
    • None
    • Replication
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      SERVER-92236 and more generally SERVER-92333 describe the problem where if a cancellation source is long-lived and cancelToken.onCancel() futures keep getting associated to it, it creates what is effectively a memory leak, as those futures will consume memory which doesn't get released under normal circumstances.

       

      It appears that TransactionCoordinator is vulnerable to this problem:

      This leak happens for every coordinated (i.e. multi-shard) transaction.

      The stack trace associated to the leak is:

      tcmalloc::tcmalloc_internal::SampleifyAllocation()
      tcmalloc::tcmalloc_internal::alloc_small_sampled_hooks_or_perthread<>()
      mongo::future_details::SharedStateImpl<>::addChild()
      mongo::CancellationToken::onCancel()
      mongo::WaitForMajorityServiceImplBase::waitUntilMajority()
      mongo::(anonymous namespace)::waitForMajorityWithHangFailpoint()
      mongo::unique_function<>::makeImpl<>()::SpecificImpl::call()
      mongo::future_details::FutureImpl<>::then<>()::{lambda()#1}::operator()()
      mongo::future_details::FutureImpl<>::generalImpl<>()
      mongo::Promise<>::setWith<>()
      mongo::unique_function<>::makeImpl<>()::SpecificImpl::call()
      mongo::unique_function<>::makeImpl<>()::SpecificImpl::call()
      mongo::executor::ThreadPoolTaskExecutor::runCallback()
      mongo::unique_function<>::makeImpl<>()::SpecificImpl::call()
      mongo::ThreadPool::Impl::_doOneTask()
      mongo::ThreadPool::Impl::_consumeTasks()
      mongo::ThreadPool::Impl::_workerThreadBody()
      std::thread::_State_impl<>::_M_run()
      execute_native_thread_routine
      

       

      A reproducer is attached.

        1. SERVER-103841-repro.js
          2 kB
          Joan Bruguera Micó

            Assignee:
            Unassigned Unassigned
            Reporter:
            joan.bruguera-mico@mongodb.com Joan Bruguera Micó
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated: