diff options
author | Jens Geyer <jensg@apache.org> | 2014-12-04 21:49:07 +0100 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2014-12-04 21:52:28 +0100 |
commit | fb05cf67db2d9515186acb94aa41160d2a1281fc (patch) | |
tree | f5ad7b44dd4dedeb391d2f9788df5540b845fe0e /lib/cpp | |
parent | 78c57e1720995821d80009dd99698b3a34f52e93 (diff) | |
download | thrift-fb05cf67db2d9515186acb94aa41160d2a1281fc.tar.gz |
THRIFT-2789 TNonblockingServer leaks socket FD's under load
Client: C++
Patch: Sergey <drigh@deviantart.com> and Qiao Mu <qiaomuf@gmail.com>
Diffstat (limited to 'lib/cpp')
-rw-r--r-- | lib/cpp/src/thrift/concurrency/ThreadManager.cpp | 6 | ||||
-rw-r--r-- | lib/cpp/src/thrift/server/TNonblockingServer.cpp | 11 |
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp index 9ff2c9a91..cc2c3c671 100644 --- a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp +++ b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp @@ -290,8 +290,10 @@ public: if (task->state_ == ThreadManager::Task::EXECUTING) { try { task->run(); - } catch (...) { - // XXX need to log this + } catch(const std::exception& e) { + GlobalOutput.printf("[ERROR] task->run() raised an exception: %s", e.what()); + } catch(...) { + GlobalOutput.printf("[ERROR] task->run() raised an unknown exception"); } } } diff --git a/lib/cpp/src/thrift/server/TNonblockingServer.cpp b/lib/cpp/src/thrift/server/TNonblockingServer.cpp index 1cfdef8fa..9833f10e3 100644 --- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp +++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp @@ -283,6 +283,7 @@ public: void forceClose() { appState_ = APP_CLOSE_CONNECTION; if (!notifyIOThread()) { + close(); throw TException("TConnection::forceClose: failed write on notify pipe"); } } @@ -342,6 +343,8 @@ public: // Signal completion back to the libevent thread via a pipe if (!connection_->notifyIOThread()) { + GlobalOutput.printf("TNonblockingServer: failed to notifyIOThread, closing."); + connection_->close(); throw TException("TNonblockingServer::Task::run: failed write on notify pipe"); } } @@ -568,6 +571,9 @@ void TNonblockingServer::TConnection::transition() { // The ThreadManager is not ready to handle any more tasks (it's probably shutting down). GlobalOutput.printf("IllegalStateException: Server::process() %s", ise.what()); close(); + } catch (TimedOutException& to) { + GlobalOutput.printf("[ERROR] TimedOutException: Server::process() %s", to.what()); + close(); } // Set this connection idle so that libevent doesn't process more @@ -969,7 +975,10 @@ void TNonblockingServer::handleEvent(THRIFT_SOCKET fd, short which) { if (clientConnection->getIOThreadNumber() == 0) { clientConnection->transition(); } else { - clientConnection->notifyIOThread(); + if (!clientConnection->notifyIOThread()) { + GlobalOutput.perror("[ERROR] notifyIOThread failed on fresh connection, closing", errno); + returnConnection(clientConnection); + } } // addrLen is written by the accept() call, so needs to be set before the next call. |