From 23360b3f6bed774a0c0007069c21201ce2c66d6e Mon Sep 17 00:00:00 2001 From: ConfX <114765570+teamconfx@users.noreply.github.com> Date: Thu, 14 Sep 2023 18:53:31 -0400 Subject: [PATCH] HADOOP-18824. ZKDelegationTokenSecretManager causes ArithmeticException due to improper numRetries value checking (#6052) --- .../delegation/ZKDelegationTokenSecretManager.java | 2 +- .../TestZKDelegationTokenSecretManager.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java index fb9a2951f5..34642ccdad 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/ZKDelegationTokenSecretManager.java @@ -222,7 +222,7 @@ public ZKDelegationTokenSecretManager(Configuration conf) { ZK_DTSM_ZK_CONNECTION_TIMEOUT_DEFAULT) ) .retryPolicy( - new RetryNTimes(numRetries, sessionT / numRetries)); + new RetryNTimes(numRetries, numRetries == 0 ? 0 : sessionT / numRetries)); } catch (Exception ex) { throw new RuntimeException("Could not Load ZK acls or auth: " + ex, ex); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java index e92a25ea0e..469d87ab30 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/token/delegation/TestZKDelegationTokenSecretManager.java @@ -106,10 +106,22 @@ protected Configuration getSecretConf(String connectString) { @SuppressWarnings("unchecked") @Test public void testMultiNodeOperations() throws Exception { + testMultiNodeOperationsImpl(false); + } + + @Test + public void testMultiNodeOperationsWithZeroRetry() throws Exception { + testMultiNodeOperationsImpl(true); + } + + public void testMultiNodeOperationsImpl(boolean setZeroRetry) throws Exception { for (int i = 0; i < TEST_RETRIES; i++) { DelegationTokenManager tm1, tm2 = null; String connectString = zkServer.getConnectString(); Configuration conf = getSecretConf(connectString); + if (setZeroRetry) { + conf.setInt(ZKDelegationTokenSecretManager.ZK_DTSM_ZK_NUM_RETRIES, 0); + } tm1 = new DelegationTokenManager(conf, new Text("bla")); tm1.init(); tm2 = new DelegationTokenManager(conf, new Text("bla"));