From 19e42ac4c41d0a2bbdc8094c2efeed5e28e0ed75 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Mon, 7 Sep 2015 17:46:08 -0400 Subject: [PATCH] fix potential crash in websocket --- src/network/http/websocket.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/network/http/websocket.cpp b/src/network/http/websocket.cpp index ee1041d..cbb92ae 100644 --- a/src/network/http/websocket.cpp +++ b/src/network/http/websocket.cpp @@ -196,7 +196,11 @@ namespace fc { namespace http { wdump(("server")(msg->get_payload())); //std::cerr<<"recv: "<get_payload()<<"\n"; auto payload = msg->get_payload(); - fc::async([=](){ current_con->second->on_message( payload ); }); + std::shared_ptr con = current_con->second; + ++_pending_messages; + auto f = fc::async([this,con,payload](){ if( _pending_messages ) --_pending_messages; con->on_message( payload ); }); + if( _pending_messages > 100 ) f.wait(); + }).wait(); }); @@ -274,6 +278,7 @@ namespace fc { namespace http { websocket_server_type _server; on_connection_handler _on_connection; fc::promise::ptr _closed; + uint32_t _pending_messages = 0; }; class websocket_tls_server_impl @@ -315,8 +320,8 @@ namespace fc { namespace http { auto current_con = _connections.find(hdl); assert( current_con != _connections.end() ); auto received = msg->get_payload(); - wdump((received)); - fc::async([=](){ current_con->second->on_message( received ); }); + std::shared_ptr con = current_con->second; + fc::async([con,received](){ con->on_message( received ); }); }).wait(); });