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
diff --git a/lib/cpp/src/thrift/server/TNonblockingServer.cpp b/lib/cpp/src/thrift/server/TNonblockingServer.cpp
index 2cf64f8..c03327d 100644
--- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp
@@ -591,21 +591,24 @@
// 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 {