From d4fa706dcab91f85153f4243eaa28eb604df1290 Mon Sep 17 00:00:00 2001 From: Changli Gao Date: Fri, 10 Mar 2017 13:25:43 +0800 Subject: [PATCH] THRIFT-4160: Fix use closed(freed) connections in non-blocking server Client: cpp When failing to add tasks into the thread manager, we close the corresponding connections, then set the flags of these connections, which have been already freed. We should decrease the number of active processors. This closes #1211 --- lib/cpp/src/thrift/server/TNonblockingServer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/cpp/src/thrift/server/TNonblockingServer.cpp b/lib/cpp/src/thrift/server/TNonblockingServer.cpp index 2cf64f8df3a..c03327d0dc4 100644 --- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp +++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp @@ -591,21 +591,24 @@ void TNonblockingServer::TConnection::transition() { // The application is now waiting on the task to finish appState_ = APP_WAIT_TASK; + // Set this connection idle so that libevent doesn't process more + // data on it while we're still waiting for the threadmanager to + // finish this task + setIdle(); + try { server_->addTask(task); } catch (IllegalStateException& ise) { // The ThreadManager is not ready to handle any more tasks (it's probably shutting down). GlobalOutput.printf("IllegalStateException: Server::process() %s", ise.what()); + server_->decrementActiveProcessors(); close(); } catch (TimedOutException& to) { GlobalOutput.printf("[ERROR] TimedOutException: Server::process() %s", to.what()); + server_->decrementActiveProcessors(); close(); } - // Set this connection idle so that libevent doesn't process more - // data on it while we're still waiting for the threadmanager to - // finish this task - setIdle(); return; } else { try {