[Boost-bugs] [Boost C++ Libraries] #11254: future<>::is_ready() == false in continuation function

Subject: [Boost-bugs] [Boost C++ Libraries] #11254: future<>::is_ready() == false in continuation function
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-04-30 13:40:35


#11254: future<>::is_ready() == false in continuation function
-------------------------------------------+----------------------
 Reporter: Konrad Zemek <konrad.zemek@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
  Version: Boost 1.58.0 | Severity: Problem
 Keywords: then continuation is_ready |
-------------------------------------------+----------------------
 I have a few layers of future continuations that do some work on my future
 in order to finally pass it to the client.

 Today, I've coded the following to one of the layers (non-relevant parts
 edited out for brevity):
 {{{#!c++
     auto promise = std::make_shared<boost::promise<ServerMessagePtr>>();

     // insert the promise into a container, where it will be fulfilled
     // if we receive a network reply
     m_promises.insert(acc, messageId);

     auto sendFuture = LowerLayer::send(std::move(message), retries);
     auto future = sendFuture.then(LowerLayer::m_ioServiceExecutor,
         [this, promise, messageId](auto f) mutable {
             if (f.has_exception()) {
                 this->m_promises.erase(messageId);
                 f.get();
             }

             return promise->get_future();
         });

     return future.unwrap();
 }}}

 Previously, the layer simply returned {{{promise->get_future();}}} and
 everything was well. Currently, the code causes my final continuation to
 deadlock when using a single-threaded executor (as is the case in my unit
 tests). I've added an assertion where the thread locked:

 {{{#!c++
 future.then(LowerLayer::m_ioServiceExecutor,
             [](auto f) { assert(f.is_ready()); return SvrMsg{f.get()}; }
 }}}

 Following is a trace from my unit tests:

 {{{
 communicator_test: ../object/../src/communication/layers/translator.h:108:
 one::communication::layers::Translator<LowerLayer>::communicate(const
 one::messages::ClientMessage&, int)::<lambda(auto:7)> [with auto:7 =
 boost::future<std::unique_ptr<one::clproto::ServerMessage> >; SvrMsg =
 one::messages::Pong; LowerLayer =
 one::communication::layers::Replier<one::communication::layers::Inbox<one::communication::layers::Sequencer<one::communication::layers::BinaryTranslator<one::communication::layers::Retrier<LazyConnectionPool>
> > > >]: Assertion `f.is_ready()' failed.
 [Thread 0x7ffff4627700 (LWP 21) exited]

 Program received signal SIGABRT, Aborted.
 [Switching to Thread 0x7ffff5265700 (LWP 20)]
 0x00007ffff5bd7e37 in __GI_raise (sig=sig_at_entry=6) at
 ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or
 directory.
 (gdb) bt
 #0 0x00007ffff5bd7e37 in __GI_raise (sig=sig_at_entry=6) at
 ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #1 0x00007ffff5bd9528 in __GI_abort () at abort.c:89
 #2 0x00007ffff5bd0ce6 in __assert_fail_base (fmt=0x7ffff5d20c08
 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
 assertion=assertion_at_entry=0x574473 "f.is_ready()",
     file=file_at_entry=0x574440
 "../object/../src/communication/layers/translator.h", line=line_at_entry=108,
     function=function_at_entry=0x57b540
 <_ZZZN3one13communication6layers10TranslatorINS1_7ReplierINS1_5InboxINS1_9SequencerINS1_16BinaryTranslatorINS1_7RetrierI18LazyConnectionPoolEEEEEEEEEEE11communicateINS_8messages4PongEEEDaRKNSG_13ClientMessageEiENKUlT_E_clIN5boost6futureISt10unique_ptrINS_7clproto13ServerMessageESt14default_deleteISS_EEEEEEDaT_E19__PRETTY_FUNCTION__>
 "one::communication::layers::Translator<LowerLayer>::communicate(const
 one::messages::ClientMessage&, int)::<lambda(auto:7)> [with auto:7 =
 boost::future<std::unique_ptr<one::clproto::ServerMessage> >;"...) at
 assert.c:92
 #3 0x00007ffff5bd0d92 in __GI___assert_fail (assertion=0x574473
 "f.is_ready()", file=0x574440
 "../object/../src/communication/layers/translator.h", line=108,
     function=0x57b540
 <_ZZZN3one13communication6layers10TranslatorINS1_7ReplierINS1_5InboxINS1_9SequencerINS1_16BinaryTranslatorINS1_7RetrierI18LazyConnectionPoolEEEEEEEEEEE11communicateINS_8messages4PongEEEDaRKNSG_13ClientMessageEiENKUlT_E_clIN5boost6futureISt10unique_ptrINS_7clproto13ServerMessageESt14default_deleteISS_EEEEEEDaT_E19__PRETTY_FUNCTION__>
 "one::communication::layers::Translator<LowerLayer>::communicate(const
 one::messages::ClientMessage&, int)::<lambda(auto:7)> [with auto:7 =
 boost::future<std::unique_ptr<one::clproto::ServerMessage> >;"...) at
 assert.c:101
 #4 0x00000000005014bf in
 _ZZN3one13communication6layers10TranslatorINS1_7ReplierINS1_5InboxINS1_9SequencerINS1_16BinaryTranslatorINS1_7RetrierI18LazyConnectionPoolEEEEEEEEEEE11communicateINS_8messages4PongEEEDaRKNSG_13ClientMessageEiENKUlT_E_clIN5boost6futureISt10unique_ptrINS_7clproto13ServerMessageESt14default_deleteISS_EEEEEEDaT_
 (__closure=0x7ef090, f=...) at
 ../object/../src/communication/layers/translator.h:108
 #5 0x0000000000530a90 in
 _ZN5boost6detail41future_executor_continuation_shared_stateINS_9executors17basic_thread_poolENS_6futureISt10unique_ptrIN3one7clproto13ServerMessageESt14default_deleteIS8_EEEENS6_8messages4PongEZNS6_13communication6layers10TranslatorINSG_7ReplierINSG_5InboxINSG_9SequencerINSG_16BinaryTranslatorINSG_7RetrierI18LazyConnectionPoolEEEEEEEEEEE11communicateISE_EEDaRKNSD_13ClientMessageEiEUlT_E_E3runENS_10shared_ptrINS0_17shared_state_baseEEE
 (
     that_=...) at /usr/include/boost/thread/future.hpp:4281
 #6 0x00000000005307b2 in
 _ZN5boost6detail6run_itINS0_41future_executor_continuation_shared_stateINS_9executors17basic_thread_poolENS_6futureISt10unique_ptrIN3one7clproto13ServerMessageESt14default_deleteIS9_EEEENS7_8messages4PongEZNS7_13communication6layers10TranslatorINSH_7ReplierINSH_5InboxINSH_9SequencerINSH_16BinaryTranslatorINSH_7RetrierI18LazyConnectionPoolEEEEEEEEEEE11communicateISF_EEDaRKNSE_13ClientMessageEiEUlT_E_EEEclEv
 (this=0x7fffec000a88)
     at /usr/include/boost/thread/future.hpp:4252
 #7 0x0000000000530548 in
 _ZN5boost6detail16nullary_functionIFvvEE9impl_typeINS0_6run_itINS0_41future_executor_continuation_shared_stateINS_9executors17basic_thread_poolENS_6futureISt10unique_ptrIN3one7clproto13ServerMessageESt14default_deleteISD_EEEENSB_8messages4PongEZNSB_13communication6layers10TranslatorINSL_7ReplierINSL_5InboxINSL_9SequencerINSL_16BinaryTranslatorINSL_7RetrierI18LazyConnectionPoolEEEEEEEEEEE11communicateISJ_EEDaRKNSI_13ClientMessageEiEUlT_E_EEEEE4callEv
 (this=0x7fffec000a80) at
 /usr/include/boost/thread/detail/nullary_function.hpp:52
 #8 0x00000000004fa3fd in boost::detail::nullary_function<void
 ()>::operator()() (this=0x7ffff5264dd0) at
 /usr/include/boost/thread/detail/nullary_function.hpp:125
 #9 0x0000000000500325 in
 boost::executors::basic_thread_pool::worker_thread (this=0x7edb10) at
 /usr/include/boost/thread/executors/basic_thread_pool.hpp:92
 #10 0x000000000052e55b in boost::detail::invoke<void
 (boost::executors::basic_thread_pool::*)(),
 boost::executors::basic_thread_pool<>*>(void
 (boost::executors::basic_thread_pool::*&&)(),
 boost::executors::basic_thread_pool<>*&&,
 (boost::executors::basic_thread_pool<>*&&)...) (f=<unknown type in
 /home/kzemek/plgrid/helpers/debug/test/unit/communicator_test, CU 0xa555,
 DIE 0xa1c35>,
     a0=<unknown type in
 /home/kzemek/plgrid/helpers/debug/test/unit/communicator_test, CU 0xa555,
 DIE 0xa1c3a>) at /usr/include/boost/thread/detail/invoke.hpp:77
 #11 0x000000000052c5fd in boost::detail::thread_data<void
 (boost::executors::basic_thread_pool::*)(),
 boost::executors::basic_thread_pool*>::run2<1ul> (this=0x7ec1d0) at
 /usr/include/boost/thread/detail/thread.hpp:75
 #12 0x0000000000529c02 in boost::detail::thread_data<void
 (boost::executors::basic_thread_pool::*)(),
 boost::executors::basic_thread_pool*>::run (this=0x7ec1d0) at
 /usr/include/boost/thread/detail/thread.hpp:81
 #13 0x00007ffff766fd8a in ?? () from /usr/lib/x86_64-linux-
 gnu/libboost_thread.so.1.58.0
 #14 0x00007ffff72450a5 in start_thread (arg=0x7ffff5265700) at
 pthread_create.c:309
 #15 0x00007ffff5c9acfd in clone () at
 ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
 }}}

 I haven't yet found an exact reason for the failure.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11254>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:18 UTC