diff --git a/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/client/KerberosAuthenticator.java b/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/client/KerberosAuthenticator.java index 3bfa349880..c035dd44ce 100644 --- a/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/client/KerberosAuthenticator.java +++ b/hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/client/KerberosAuthenticator.java @@ -183,8 +183,9 @@ public void authenticate(URL url, AuthenticatedURL.Token token) if (!token.isSet()) { this.url = url; base64 = new Base64(0); + HttpURLConnection conn = null; try { - HttpURLConnection conn = token.openConnection(url, connConfigurator); + conn = token.openConnection(url, connConfigurator); conn.setRequestMethod(AUTH_HTTP_METHOD); conn.connect(); @@ -218,6 +219,10 @@ public void authenticate(URL url, AuthenticatedURL.Token token) } catch (AuthenticationException ex){ throw wrapExceptionWithMessage(ex, "Error while authenticating with endpoint: " + url); + } finally { + if (conn != null) { + conn.disconnect(); + } } } } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/web/DelegationTokenAuthenticator.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/web/DelegationTokenAuthenticator.java index 4e2ee4fdbe..8546a76c1a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/web/DelegationTokenAuthenticator.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/web/DelegationTokenAuthenticator.java @@ -312,8 +312,9 @@ private Map doDelegationTokenOperation(URL url, dt = ((DelegationTokenAuthenticatedURL.Token) token).getDelegationToken(); ((DelegationTokenAuthenticatedURL.Token) token).setDelegationToken(null); } + HttpURLConnection conn = null; try { - HttpURLConnection conn = aUrl.openConnection(url, token); + conn = aUrl.openConnection(url, token); conn.setRequestMethod(operation.getHttpMethod()); HttpExceptionUtils.validateResponse(conn, HttpURLConnection.HTTP_OK); if (hasResponse) { @@ -339,6 +340,9 @@ private Map doDelegationTokenOperation(URL url, if (dt != null) { ((DelegationTokenAuthenticatedURL.Token) token).setDelegationToken(dt); } + if (conn != null) { + conn.disconnect(); + } } return ret; }