From a2221e20543331f38cceae26d884782140810499 Mon Sep 17 00:00:00 2001 From: Pavel Baykov Date: Mon, 4 Apr 2022 11:06:16 -0300 Subject: [PATCH] fix cores: don't use promise in websocket when failure, use FC_CAPTURE_AND_LOG in cleanup_cancelled_task --- src/network/http/websocket.cpp | 9 +++++---- tests/thread/task_cancel.cpp | 7 ++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/network/http/websocket.cpp b/src/network/http/websocket.cpp index 2d446e5..db5ae9b 100755 --- a/src/network/http/websocket.cpp +++ b/src/network/http/websocket.cpp @@ -434,8 +434,9 @@ namespace fc { namespace http { _client_thread.async( [&](){ if( _connection ) _connection->closed(); _connection.reset(); } ).wait(); if( _connected && !_connected->ready() ) _connected->set_exception( exception_ptr( new FC_EXCEPTION( exception, "${message}", ("message",message)) ) ); - if( _closed ) - _closed->set_value(); + //if( _closed && !_closed->ready() ) + // _closed->set_value(); + _failed = true; }); _client.init_asio( &fc::asio::default_io_service() ); @@ -447,11 +448,11 @@ namespace fc { namespace http { _connection->close(0, "client closed"); _connection.reset(); } - if( _closed ) + if( _closed && !_failed) _closed->wait(); } - + bool _failed = false; fc::promise::ptr _connected; fc::promise::ptr _closed; fc::thread& _client_thread; diff --git a/tests/thread/task_cancel.cpp b/tests/thread/task_cancel.cpp index 3435f39..cc26e4f 100755 --- a/tests/thread/task_cancel.cpp +++ b/tests/thread/task_cancel.cpp @@ -191,11 +191,8 @@ BOOST_AUTO_TEST_CASE( cleanup_cancelled_task ) { fc::usleep(fc::seconds(5)); BOOST_TEST_MESSAGE("Finsihed usleep in async task, leaving the task's functor"); - } - catch (...) - { - BOOST_TEST_MESSAGE("Caught exception in async task, leaving the task's functor"); - } + } FC_CAPTURE_AND_LOG( (some_string) ); + }, "test_task"); std::weak_ptr weak_string_ptr(some_string); some_string.reset();