From 3a96e7c1b6a834570de5ea059eda1fc28ea66199 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 10 Jan 2013 09:55:48 -0800 Subject: [PATCH] A surprisingly simple fix to the InfoSub/websocketpp deadlock. --- src/cpp/ripple/WSConnection.h | 9 +++++++++ src/cpp/ripple/WSHandler.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/cpp/ripple/WSConnection.h b/src/cpp/ripple/WSConnection.h index 0116f1f48..6bc97e6ca 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 887303b29..793ca98b8 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)