Opened 7 years ago

Closed 6 years ago

#11951 closed Bugs (fixed)

Memory leak in boost::when_all

Reported by: snizovtsev@… Owned by: viboes
Milestone: Boost 1.62.0 Component: thread
Version: Boost 1.60.0 Severity: Regression
Keywords: future continuation leak Cc:

Description

After trying to identify the source of huge memory leak in our product we found that problem sits inside boost::when_all.

I have written a minimal program to demonstrate it. It simply constructs many promises, extracts the future from them and assign continuation to boost::when_all future. Then it waits for completition and loop.

Run htop and see how memory infinitly consumes in time at ~300-400 kb/sec. I have run this test on OS X (El Capitan) and Ubuntu 15.10. On Linux also virtual memory (address space) consumed at ~1 GB/sec rate!

ifdef-ed part of code are used to run on valgrind and test that future's target objects are NOT leaked.

Attachments (1)

when_all.cc (1.9 KB ) - added by snizovtsev@… 7 years ago.

Download all attachments as: .zip

Change History (9)

by snizovtsev@…, 7 years ago

Attachment: when_all.cc added

comment:1 by snizovtsev@…, 7 years ago

Valgrind output:

==3289== 5,760 bytes in 10 blocks are possibly lost in loss record 6 of 7
==3289==    at 0x4C2DB95: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3289==    by 0x40134B4: allocate_dtv (dl-tls.c:322)
==3289==    by 0x40134B4: _dl_allocate_tls (dl-tls.c:544)
==3289==    by 0x5BCE0D2: allocate_stack (allocatestack.c:588)
==3289==    by 0x5BCE0D2: pthread_create@@GLIBC_2.2.5 (pthread_create.c:537)
==3289==    by 0x504CE28: boost::thread::start_thread_noexcept() (in /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.60.0)
==3289==    by 0x40D15D: boost::thread::start_thread() (thread.hpp:178)
==3289==    by 0x4236E9: boost::thread::thread<void (*)(boost::shared_ptr<boost::detail::shared_state_base>), boost::shared_ptr<boost::detail::shared_state_base> >(void (*)(boost::shared_ptr<boost::detail::shared_state_base>), boost::shared_ptr<boost::detail::shared_state_base>, boost::disable_if<boost::thread_detail::is_convertible<void (*&)(boost::shared_ptr<boost::detail::shared_state_base>), boost::thread_attributes>, boost::thread::dummy*>::type) (thread.hpp:393)
==3289==    by 0x420233: boost::detail::future_when_all_vector_shared_state<boost::future<Int> >::init() (future.hpp:5211)
==3289==    by 0x41B25E: boost::disable_if<boost::is_future_type<std::move_iterator<__gnu_cxx::__normal_iterator<boost::future<Int>*, std::vector<boost::future<Int>, std::allocator<boost::future<Int> > > > > >, boost::future<std::vector<std::move_iterator<__gnu_cxx::__normal_iterator<boost::future<Int>*, std::vector<boost::future<Int>, std::allocator<boost::future<Int> > > > >::value_type, std::allocator<std::move_iterator<__gnu_cxx::__normal_iterator<boost::future<Int>*, std::vector<boost::future<Int>, std::allocator<boost::future<Int> > > > >::value_type> > > >::type boost::when_all<std::move_iterator<__gnu_cxx::__normal_iterator<boost::future<Int>*, std::vector<boost::future<Int>, std::allocator<boost::future<Int> > > > > >(std::move_iterator<__gnu_cxx::__normal_iterator<boost::future<Int>*, std::vector<boost::future<Int>, std::allocator<boost::future<Int> > > > >, std::move_iterator<__gnu_cxx::__normal_iterator<boost::future<Int>*, std::vector<boost::future<Int>, std::allocator<boost::future<Int> > > > >) (future.hpp:5493)
==3289==    by 0x4145ED: boost::future<void> iter<Int, 2ul>(int) (when_all.cc:85)
==3289==    by 0x40B328: main (when_all.cc:99)

comment:2 by viboes, 7 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:3 by viboes, 6 years ago

Sorry for been late.

It seems that the source and the stack doesn't match. Could you reload them?

comment:4 by viboes, 6 years ago

See also #12220

comment:5 by viboes, 6 years ago

I should use a weak_ptr instead but for the time been I don't reach to make it working. Any help much appreciated.

comment:6 by viboes, 6 years ago

I have committed

https://github.com/boostorg/thread/commit/5450e98c6bd2515388de1d3d97431cf5374319e7

Please, could you tell me if this fixes the issue?

comment:7 by viboes, 6 years ago

Milestone: To Be DeterminedBoost 1.62.0

comment:8 by viboes, 6 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.