[ 
https://issues.apache.org/jira/browse/THRIFT-3814?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15273558#comment-15273558
 ] 

ASF GitHub Bot commented on THRIFT-3814:
----------------------------------------

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

    https://github.com/apache/thrift/pull/1005#discussion_r62283672
  
    --- 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 --
    
    It's a test failure so my intention here was "no need to catch" and let it 
die with std::terminate with exception log.
    The original `error` flag was needed for retrying from the main thread.


> Fix contention in TNonblockingServerTest
> ----------------------------------------
>
>                 Key: THRIFT-3814
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3814
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library, Test Suite
>            Reporter: Aki Sukegawa
>            Assignee: Aki Sukegawa
>              Labels: test-stability
>
> User provided event_base could possibly be deleted before the server.
> Hopefully this fixes the occasional failure on Travis-CI.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to