Skip to content

Commit

Permalink
THRIFT-4160: Fix use closed(freed) connections in non-blocking server
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xiaosuo authored and jeking3 committed Apr 3, 2017
1 parent df3223c commit d4fa706
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/cpp/src/thrift/server/TNonblockingServer.cpp
Expand Up @@ -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 {
Expand Down

0 comments on commit d4fa706

Please sign in to comment.