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

This commit is contained in:
Pavel Baykov 2022-04-05 22:46:48 +00:00 committed by serkixenos
parent 6171e973c7
commit 07eaa68334
7 changed files with 31 additions and 22 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

@ -27,6 +27,7 @@ namespace fc {
}
void promise_base::cancel(const char* reason /* = nullptr */){
synchronized(_spin_yield)
// wlog("${desc} canceled!", ("desc", _desc? _desc : ""));
_canceled = true;
#ifndef NDEBUG

View file

@ -596,7 +596,12 @@ namespace fc {
else if( timeout_time != time_point::min() )
{
// there may be tasks that have been canceled we should filter them out now
// rather than waiting...
// rather than waiting...
//
if (current->canceled){
return;
}
/* This bit is kind of sloppy -- this wait was originally implemented as a wait

View file

@ -139,31 +139,36 @@ BOOST_AUTO_TEST_CASE(blowfish_chain_test)
BOOST_CHECK_EQUAL( 32, fc::from_hex( chain_test_cbc.c_str(), (char*) cipher, sizeof(cipher) ) );
fc::blowfish fish;
fish.start( key, sizeof(key), fc::sblock( from_bytes( iv ), from_bytes( iv + 4 ) ) );
fish.encrypt( (unsigned char*) chain_test_plain.c_str(), out, sizeof(out), fc::blowfish::CBC );
char buffer[32];
memset(buffer, 0, sizeof(buffer));
memcpy(buffer, chain_test_plain.c_str(), std::min(sizeof(buffer), chain_test_plain.size()));
fish.encrypt( (unsigned char*) buffer, out, sizeof(out), fc::blowfish::CBC );
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
fish.reset_chain();
fish.decrypt( out, sizeof(out), fc::blowfish::CBC );
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
fish.reset_chain();
fish.encrypt( out, sizeof(out), fc::blowfish::CBC );
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
fish.reset_chain();
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CBC );
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
BOOST_CHECK_EQUAL( 29, fc::from_hex( chain_test_cfb.c_str(), (char*) cipher, sizeof(cipher) ) );
fish.reset_chain();
fish.encrypt( (unsigned char*) chain_test_plain.c_str(), out, sizeof(out), fc::blowfish::CFB );
fish.encrypt( (unsigned char*) buffer, out, sizeof(out), fc::blowfish::CFB );
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
fish.reset_chain(); memset( out + 29, 0, 3 );
fish.decrypt( out, sizeof(out), fc::blowfish::CFB );
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
fish.reset_chain(); memset( out + 29, 0, 3 );
fish.encrypt( out, sizeof(out), fc::blowfish::CFB );
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
fish.reset_chain(); memset( out + 29, 0, 3 );
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CFB );
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -47,9 +47,9 @@ BOOST_AUTO_TEST_CASE(real128_test)
BOOST_CHECK_EQUAL( real128(uint64_t(-1)).to_uint64(), uint64_t(-1) );
wdump( (ten)(two)(twenty) );
wdump((real128("12345.6789")) );
wdump( (ten/3*3) );
//wdump( (ten)(two)(twenty) );
//wdump((real128("12345.6789")) );
//wdump( (ten/3*3) );
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -51,12 +51,12 @@ BOOST_AUTO_TEST_CASE( nested_objects_test )
auto create_nested_object = []( uint32_t level )
{
ilog( "Creating nested object with ${lv} level(s)", ("lv",level) );
//ilog( "Creating nested object with ${lv} level(s)", ("lv",level) );
fc::test::item nested;
for( uint32_t i = 1; i <= level; i++ )
{
if( i % 100 == 0 )
ilog( "Creating level ${lv}", ("lv",i) );
//if( i % 100 == 0 )
// ilog( "Creating level ${lv}", ("lv",i) );
fc::test::item_wrapper wp( std::move(nested) );
nested = fc::test::item( std::move(wp), i );
}

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();