fix cores: don't use promise in websocket when failure, use FC_CAPTURE_AND_LOG in cleanup_cancelled_task

This commit is contained in:
Pavel Baykov 2022-04-04 11:06:16 -03:00
parent 30296957f7
commit a2221e2054
2 changed files with 7 additions and 9 deletions

View file

@ -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<void>::ptr _connected;
fc::promise<void>::ptr _closed;
fc::thread& _client_thread;

View file

@ -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<std::string> weak_string_ptr(some_string);
some_string.reset();