From 7e58eec620248bfc5a36032f3cc25dd8ddeddc8a Mon Sep 17 00:00:00 2001 From: Xiao Chen Date: Mon, 5 Dec 2016 09:34:39 -0800 Subject: [PATCH] HADOOP-13847. KMSWebApp should close KeyProviderCryptoExtension. Contributed by John Zhuge. (cherry picked from commit 291df5c7fb713d5442ee29eb3f272127afb05a3c) --- .../hadoop/crypto/key/KeyProviderCryptoExtension.java | 5 +++-- .../org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProviderCryptoExtension.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProviderCryptoExtension.java index 9b60ff6c035..680a3671839 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProviderCryptoExtension.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/KeyProviderCryptoExtension.java @@ -427,8 +427,9 @@ public class KeyProviderCryptoExtension extends @Override public void close() throws IOException { - if (getKeyProvider() != null) { - getKeyProvider().close(); + KeyProvider provider = getKeyProvider(); + if (provider != null && provider != this) { + provider.close(); } } diff --git a/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java b/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java index 763f2076067..5772036a388 100644 --- a/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java +++ b/hadoop-common-project/hadoop-kms/src/main/java/org/apache/hadoop/crypto/key/kms/server/KMSWebApp.java @@ -40,9 +40,9 @@ import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import java.io.File; +import java.io.IOException; import java.net.URI; import java.net.URL; -import java.util.List; @InterfaceAudience.Private public class KMSWebApp implements ServletContextListener { @@ -215,6 +215,11 @@ public class KMSWebApp implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent sce) { + try { + keyProviderCryptoExtension.close(); + } catch (IOException ioe) { + LOG.error("Error closing KeyProviderCryptoExtension", ioe); + } kmsAudit.shutdown(); kmsAcls.stopReloader(); jmxReporter.stop();