Github user jeking3 commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/980#discussion_r60227644
  
    --- Diff: lib/cpp/src/thrift/server/TThreadedServer.cpp ---
    @@ -90,31 +95,69 @@ TThreadedServer::~TThreadedServer() {
     }
     
     void TThreadedServer::serve() {
    +  threadFactory_->setDetached(false);
       TServerFramework::serve();
     
    -  // Drain all clients - no more will arrive
    -  try {
    -    Synchronized s(clientsMonitor_);
    -    while (getConcurrentClientCount() > 0) {
    -      clientsMonitor_.wait();
    -    }
    -  } catch (TException& tx) {
    -    string errStr = string("TThreadedServer: Exception joining workers: ") 
+ tx.what();
    -    GlobalOutput(errStr.c_str());
    +  // Ensure post-condition of no active clients
    +  Synchronized s(clientMonitor_);
    +  while (!activeClientMap_.empty()) {
    +    clientMonitor_.wait();
    +  }
    +
    +  drainDeadClients();
    +}
    +
    +void TThreadedServer::drainDeadClients() {
    +  // we're in a monitor here
    +  while (!deadClientMap_.empty()) {
    +    ClientMap::iterator it = deadClientMap_.begin();
    +    it->second->join();
    +    deadClientMap_.erase(it);
       }
     }
     
     void TThreadedServer::onClientConnected(const 
shared_ptr<TConnectedClient>& pClient) {
    -  threadFactory_->newThread(pClient)->start();
    +  Synchronized sync(clientMonitor_);
    +  activeClientMap_.insert(ClientMap::value_type(pClient.get(), 
boost::make_shared<TConnectedClientRunner>(pClient)));
    +  ClientMap::iterator it = activeClientMap_.find(pClient.get());
    --- End diff --
    
    I implemented this suggestion.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to