From: David Reiss Date: Tue, 7 Oct 2008 21:39:19 +0000 (+0000) Subject: THRIFT-149. cpp: Make TNonblockingServer handle a shut-down ThreadManager X-Git-Tag: 0.2.0~436 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=e11f3073f7411e7b0508047850fcb42b331a2e5e;p=common%2Fthrift.git THRIFT-149. cpp: Make TNonblockingServer handle a shut-down ThreadManager This is a step toward implementing a graceful shutdown. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@702644 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp index bf9a5b17..c0be8ef4 100644 --- a/lib/cpp/src/server/TNonblockingServer.cpp +++ b/lib/cpp/src/server/TNonblockingServer.cpp @@ -5,6 +5,7 @@ // http://developers.facebook.com/thrift/ #include "TNonblockingServer.h" +#include #include #include @@ -19,6 +20,7 @@ namespace facebook { namespace thrift { namespace server { using namespace facebook::thrift::protocol; using namespace facebook::thrift::transport; +using namespace facebook::thrift::concurrency; using namespace std; class TConnection::Task: public Runnable { @@ -252,7 +254,13 @@ void TConnection::transition() { GlobalOutput("TNonblockingServer::serve(): coult not event_add"); return; } - server_->addTask(task); + try { + server_->addTask(task); + } catch (IllegalStateException & ise) { + // The ThreadManager is not ready to handle any more tasks (it's probably shutting down). + GlobalOutput.printf(stderr, "IllegalStateException: Server::process() %s", ise.what()); + close(); + } // Set this connection idle so that libevent doesn't process more // data on it while we're still waiting for the threadmanager to