Github user jeking3 commented on a diff in the pull request: https://github.com/apache/thrift/pull/980#discussion_r59390673 --- Diff: lib/cpp/src/thrift/server/TThreadedServer.h --- @@ -83,12 +88,56 @@ class TThreadedServer : public TServerFramework { virtual void serve(); protected: + /** + * Drain recently connected clients by joining their threads - this is done lazily because + * we cannot do it inside the thread context that is disconnecting. + */ + virtual void drainDeadClients(); + + /** + * Implementation of TServerFramework::onClientConnected + */ virtual void onClientConnected(const boost::shared_ptr<TConnectedClient>& pClient) /* override */; - virtual void onClientDisconnected(TConnectedClient* pClient) /* override */; + + /** + * Implementation of TServerFramework::onClientDisconnected + */ + virtual void onClientDisconnected(TConnectedClient *pClient) /* override */; boost::shared_ptr<apache::thrift::concurrency::ThreadFactory> threadFactory_; - apache::thrift::concurrency::Monitor clientsMonitor_; + + /** + * A helper wrapper used to wrap the client in something we can use to maintain + * the lifetime of the connected client within a detached thread. --- End diff -- I made this change and it will only work if I modify each of the thread implementations to release the smart_ptr to runnable in the thread class after the thread runs. I assume this is acceptable; once the runnable runs we don't need the thread smart_ptr holding on to it any more; TServerFramework requires the TConnectedClient (the runnable) to be destroyed when the client disconnects to function properly.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---