From fdef47ea2bbb1802deee4f10407c40cd32c42d52 Mon Sep 17 00:00:00 2001 From: Aditya Agarwal Date: Wed, 7 Feb 2007 03:54:18 +0000 Subject: [PATCH] -- Servers should not crash on accept. Summary: - Continue running if there is an accept issue Reviewed By: slee git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664988 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/concurrency/Exception.h | 11 +++++----- lib/cpp/src/server/TSimpleServer.cpp | 26 ++++++++++++++++++------ lib/cpp/src/server/TThreadPoolServer.cpp | 20 +++++++++++++++++- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/lib/cpp/src/concurrency/Exception.h b/lib/cpp/src/concurrency/Exception.h index 67eb1530..79a7a29b 100644 --- a/lib/cpp/src/concurrency/Exception.h +++ b/lib/cpp/src/concurrency/Exception.h @@ -2,18 +2,19 @@ #define _THRIFT_CONCURRENCY_EXCEPTION_H_ 1 #include +#include namespace facebook { namespace thrift { namespace concurrency { -class NoSuchTaskException : public std::exception {}; +class NoSuchTaskException : public facebook::thrift::TException {}; -class UncancellableTaskException : public std::exception {}; +class UncancellableTaskException : public facebook::thrift::TException {}; -class InvalidArgumentException : public std::exception {}; +class InvalidArgumentException : public facebook::thrift::TException {}; -class IllegalStateException : public std::exception {}; +class IllegalStateException : public facebook::thrift::TException {}; -class TimedOutException : public std::exception {}; +class TimedOutException : public facebook::thrift::TException {}; }}} // facebook::thrift::concurrency diff --git a/lib/cpp/src/server/TSimpleServer.cpp b/lib/cpp/src/server/TSimpleServer.cpp index 1e7e7fbc..f7e26733 100644 --- a/lib/cpp/src/server/TSimpleServer.cpp +++ b/lib/cpp/src/server/TSimpleServer.cpp @@ -28,8 +28,8 @@ void TSimpleServer::serve() { } // Fetch client from server - try { - while (true) { + while (true) { + try { client = serverTransport_->accept(); inputTransport = inputTransportFactory_->getTransport(client); outputTransport = outputTransportFactory_->getTransport(client); @@ -47,14 +47,28 @@ void TSimpleServer::serve() { } catch (TException& tx) { cerr << "TSimpleServer exception: " << tx.what() << endl; } + inputTransport->close(); + outputTransport->close(); + client->close(); + } catch (TTransportException& ttx) { + inputTransport->close(); + outputTransport->close(); + client->close(); + cerr << "TServerTransport died on accept: " << ttx.what() << endl; + continue; + } catch (TException& tx) { inputTransport->close(); outputTransport->close(); client->close(); + cerr << "Some kind of accept exception: " << tx.what() << endl; + continue; + } catch (string s) { + inputTransport->close(); + outputTransport->close(); + client->close(); + cerr << "TThreadPoolServer: Unknown exception: " << s << endl; + break; } - } catch (TTransportException& ttx) { - cerr << "TServerTransport died on accept: " << ttx.what() << endl; - } catch (TException& tx) { - cerr << "Some kind of accept exception: " << tx.what() << endl; } // TODO(mcslee): Could this be a timeout case? Or always the real thing? diff --git a/lib/cpp/src/server/TThreadPoolServer.cpp b/lib/cpp/src/server/TThreadPoolServer.cpp index 8514d187..ce1b59e3 100644 --- a/lib/cpp/src/server/TThreadPoolServer.cpp +++ b/lib/cpp/src/server/TThreadPoolServer.cpp @@ -102,8 +102,26 @@ void TThreadPoolServer::serve() { outputProtocol = outputProtocolFactory_->getProtocol(outputTransport); // Add to threadmanager pool - threadManager_->add(shared_ptr(new TThreadPoolServer::Task(processor_, inputProtocol, outputProtocol))); + threadManager_->add(shared_ptr(new TThreadPoolServer::Task(processor_, + inputProtocol, + outputProtocol))); } catch (TTransportException& ttx) { + inputTransport->close(); + outputTransport->close(); + client->close(); + cerr << "TThreadPoolServer: TServerTransport died on accept: " << ttx.what() << endl; + continue; + } catch (TException& tx) { + inputTransport->close(); + outputTransport->close(); + client->close(); + cerr << "TThreadPoolServer: Caught TException: " << tx.what() << endl; + continue; + } catch (string s) { + inputTransport->close(); + outputTransport->close(); + client->close(); + cerr << "TThreadPoolServer: Unknown exception: " << s << endl; break; } } -- 2.17.1