diff --git a/src/cpp/ripple/WSHandler.h b/src/cpp/ripple/WSHandler.h index 824c690611..4d24f6f898 100644 --- a/src/cpp/ripple/WSHandler.h +++ b/src/cpp/ripple/WSHandler.h @@ -91,10 +91,17 @@ public: } void on_close(connection_ptr cpClient) - { - boost::mutex::scoped_lock sl(mMapLock); - - mMap.erase(cpClient); + { // we cannot destroy the connection while holding the map lock or we deadlock with pubLedger + typedef boost::shared_ptr< WSConnection > wsc_ptr; + wsc_ptr ptr; + { + boost::mutex::scoped_lock sl(mMapLock); + typename boost::unordered_map::iterator it = mMap.find(cpClient); + if (it == mMap.end()) + return; + ptr = it->second; // prevent the WSConnection from being destroyed until we release the lock + mMap.erase(cpClient); + } } void on_message(connection_ptr cpClient, message_ptr mpMessage)