HADOOP-16881. KerberosAuthentication does not disconnect HttpURLConnection leading to CLOSE_WAIT cnxns. Contributed by Attila Magyar.

Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org>
This commit is contained in:
Attila Magyar 2020-12-03 12:01:54 -08:00 committed by Wei-Chiu Chuang
parent f94e927bfb
commit db73e994ed
2 changed files with 11 additions and 2 deletions

View File

@ -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();
}
}
}
}

View File

@ -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;
}