This is an automated email from the ASF dual-hosted git repository.

tmarshall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit c359c557eb299174c43ed0d27ab1c2247fc94f74
Author: Thomas Tauber-Marshall <tmarsh...@cloudera.com>
AuthorDate: Thu Jan 9 16:18:24 2020 -0800

    IMPALA-8501: Fix race condition on port in RpcMgrTest
    
    RpcMgrTest previously would choose a random, unused port when starting
    and then eventually start a krpc service on the port. This resulted in
    a race condition where the port could be taken by another process
    between when it was chosen and when RpcMgrTest actually used it,
    causing RpcMgrTest to fail.
    
    This patch significantly reduces the probability of such an error
    happening by choosing the port immediately before it is used.
    
    Change-Id: I841196f8557f29816f5f2960f36fc7772233b975
    Reviewed-on: http://gerrit.cloudera.org:8080/14997
    Reviewed-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com>
    Tested-by: Impala Public Jenkins <impala-public-jenk...@cloudera.com>
---
 be/src/rpc/rpc-mgr-test.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/be/src/rpc/rpc-mgr-test.h b/be/src/rpc/rpc-mgr-test.h
index f559409..8f4871a 100644
--- a/be/src/rpc/rpc-mgr-test.h
+++ b/be/src/rpc/rpc-mgr-test.h
@@ -67,8 +67,6 @@ static string CURRENT_EXECUTABLE_PATH;
 
 namespace impala {
 
-static int32_t SERVICE_PORT = FindUnusedEphemeralPort();
-
 const static string IMPALA_HOME(getenv("IMPALA_HOME"));
 const string& SERVER_CERT =
     Substitute("$0/be/src/testutil/server-cert.pem", IMPALA_HOME);
@@ -137,7 +135,7 @@ class RpcMgrTest : public testing::Test {
   virtual void SetUp() {
     IpAddr ip;
     ASSERT_OK(HostnameToIpAddr(FLAGS_hostname, &ip));
-    krpc_address_ = MakeNetworkAddress(ip, SERVICE_PORT);
+    krpc_address_ = MakeNetworkAddress(ip, FindUnusedEphemeralPort());
     exec_env_.reset(new ExecEnv());
     ASSERT_OK(rpc_mgr_.Init(krpc_address_));
   }

Reply via email to