From ac197311ca92be84ef3dc02159e78f1cd1ee1911 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Fri, 30 Jan 2015 10:23:33 -0500 Subject: [PATCH] json_connection: save and cancel a future Hopefully this will fix a crash on exit. --- src/rpc/json_connection.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpc/json_connection.cpp b/src/rpc/json_connection.cpp index 82cd566..77a3918 100644 --- a/src/rpc/json_connection.cpp +++ b/src/rpc/json_connection.cpp @@ -21,6 +21,7 @@ namespace fc { namespace rpc { fc::buffered_ostream_ptr _out; fc::future _done; + fc::future _handle_message_future; bool _eof; uint64_t _next_id; @@ -204,7 +205,7 @@ namespace fc { namespace rpc { variant v = json::from_stream(*_in); ///ilog( "input: ${in}", ("in", v ) ); //wlog( "recv: ${line}", ("line", line) ); - fc::async([=](){ handle_message(v.get_object()); }, "json_connection handle_message"); + _handle_message_future = fc::async([=](){ handle_message(v.get_object()); }, "json_connection handle_message"); } } catch ( eof_exception& eof ) @@ -241,6 +242,8 @@ namespace fc { namespace rpc { { try { + if( my->_handle_message_future.valid() && !my->_handle_message_future.ready() ) + my->_handle_message_future.cancel_and_wait(__FUNCTION__); if( my->_done.valid() && !my->_done.ready() ) { my->_done.cancel("json_connection is destructing");