diff --git a/src/cpp/ripple/WSConnection.h b/src/cpp/ripple/WSConnection.h index 0116f1f48c..6bc97e6cae 100644 --- a/src/cpp/ripple/WSConnection.h +++ b/src/cpp/ripple/WSConnection.h @@ -54,8 +54,17 @@ public: mPingTimer(theApp->getAuxService()), mPinged(false) { setPingTimer(); } + void preDestroy() + { // sever connection + mConnection.reset(); + } + virtual ~WSConnection() { ; } + static void destroy(boost::shared_ptr< WSConnection >) + { // Just discards the reference + } + // Implement overridden functions from base class: void send(const Json::Value& jvObj) { diff --git a/src/cpp/ripple/WSHandler.h b/src/cpp/ripple/WSHandler.h index 887303b29f..793ca98b8c 100644 --- a/src/cpp/ripple/WSHandler.h +++ b/src/cpp/ripple/WSHandler.h @@ -153,6 +153,10 @@ public: ptr = it->second; // prevent the WSConnection from being destroyed until we release the lock mMap.erase(it); } + ptr->preDestroy(); // Must be done before we return + + // Must be done without holding the websocket send lock + theApp->getAuxService().post(boost::bind(&WSConnection::destroy, ptr)); } void on_message(connection_ptr cpClient, message_ptr mpMessage)