From 21c1dc7e6c5adfe80b2a452e0b534eac6a2d86c9 Mon Sep 17 00:00:00 2001 From: Pankaj Date: Mon, 17 May 2021 12:17:24 +0530 Subject: [PATCH] HBASE-25875 RegionServer failed to start with IllegalThreadStateException due to race condition in AuthenticationTokenSecretManager (#3250) * HBASE-25875 RegionServer failed to start with IllegalThreadStateException due to race condition in AuthenticationTokenSecretManager's start & retrievePassword method Signed-off-by: stack (cherry picked from commit 2126ec94f0032220fcccdca463f0f185e3653ace) --- dev-support/spotbugs-exclude.xml | 19 +++++++++++++++++++ .../hadoop/hbase/ipc/NettyRpcServer.java | 8 ++++++-- .../hadoop/hbase/ipc/SimpleRpcServer.java | 8 ++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/dev-support/spotbugs-exclude.xml b/dev-support/spotbugs-exclude.xml index 1137f5fdc14..2f0684eff4d 100644 --- a/dev-support/spotbugs-exclude.xml +++ b/dev-support/spotbugs-exclude.xml @@ -252,4 +252,23 @@ + + + + + + + + + + + + + + + diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcServer.java index f34cad5f60c..de958b8ce7d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcServer.java @@ -136,8 +136,12 @@ public class NettyRpcServer extends RpcServer { } authTokenSecretMgr = createSecretManager(); if (authTokenSecretMgr != null) { - setSecretManager(authTokenSecretMgr); - authTokenSecretMgr.start(); + // Start AuthenticationTokenSecretManager in synchronized way to avoid race conditions in + // LeaderElector start. See HBASE-25875 + synchronized (authTokenSecretMgr) { + setSecretManager(authTokenSecretMgr); + authTokenSecretMgr.start(); + } } this.authManager = new ServiceAuthorizationManager(); HBasePolicyProvider.init(conf, authManager); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcServer.java index cbcbc9a8f7a..7818572dd3d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcServer.java @@ -423,8 +423,12 @@ public class SimpleRpcServer extends RpcServer { } authTokenSecretMgr = createSecretManager(); if (authTokenSecretMgr != null) { - setSecretManager(authTokenSecretMgr); - authTokenSecretMgr.start(); + // Start AuthenticationTokenSecretManager in synchronized way to avoid race conditions in + // LeaderElector start. See HBASE-25875 + synchronized (authTokenSecretMgr) { + setSecretManager(authTokenSecretMgr); + authTokenSecretMgr.start(); + } } this.authManager = new ServiceAuthorizationManager(); HBasePolicyProvider.init(conf, authManager);