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

    https://github.com/apache/thrift/pull/1005#discussion_r62278341
  
    --- Diff: lib/cpp/test/TNonblockingServerTest.cpp ---
    @@ -47,14 +47,32 @@ struct Handler : public test::ParentServiceIf {
     class Fixture {
     private:
       struct Runner : public apache::thrift::concurrency::Runnable {
    +    int port;
    +    boost::shared_ptr<event_base> userEventBase;
    +    boost::shared_ptr<TProcessor> processor;
         boost::shared_ptr<server::TNonblockingServer> server;
    -    bool error;
    +
         virtual void run() {
    -      error = false;
    +      // When binding to explicit port, allow retrying to workaround bind 
failures on ports in use
    +      int retryCount = port ? 10 : 0;
    +      startServer(retryCount);
    +    }
    +
    +  private:
    +    void startServer(int retry_count) {
           try {
    +        server.reset(new server::TNonblockingServer(processor, port));
    +        if (userEventBase) {
    +          server->registerEvents(userEventBase.get());
    +        }
             server->serve();
    -      } catch (const TException&) {
    -        error = true;
    +      } catch (const transport::TTransportException&) {
    +        if (retry_count > 0) {
    +          ++port;
    +          startServer(retry_count - 1);
    +        } else {
    +          throw;
    --- End diff --
    
    Seems bad to throw an unhandled exception from a thread, but maybe this is 
catastrophic and rare enough that this is fine? The rest of the change looks 
good to me.


---
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