YARN-8336. Fix potential connection leak in SchedConfCLI and YarnWebServiceUtils. Contributed by Giovanni Matteo Fumarola.

This commit is contained in:
Inigo Goiri 2018-05-23 11:55:31 -07:00
parent c13dea87d9
commit e30938af12
2 changed files with 38 additions and 21 deletions

View File

@ -132,9 +132,13 @@ public int run(String[] args) throws Exception {
} }
Client webServiceClient = Client.create(); Client webServiceClient = Client.create();
WebResource webResource = webServiceClient.resource(WebAppUtils. WebResource webResource = webServiceClient
getRMWebAppURLWithScheme(getConf())); .resource(WebAppUtils.getRMWebAppURLWithScheme(getConf()));
ClientResponse response = webResource.path("ws").path("v1").path("cluster") ClientResponse response = null;
try {
response =
webResource.path("ws").path("v1").path("cluster")
.path("scheduler-conf").accept(MediaType.APPLICATION_JSON) .path("scheduler-conf").accept(MediaType.APPLICATION_JSON)
.entity(YarnWebServiceUtils.toJson(updateInfo, .entity(YarnWebServiceUtils.toJson(updateInfo,
SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON) SchedConfUpdateInfo.class), MediaType.APPLICATION_JSON)
@ -151,6 +155,12 @@ public int run(String[] args) throws Exception {
System.err.println("Configuration change unsuccessful: null response"); System.err.println("Configuration change unsuccessful: null response");
} }
return -1; return -1;
} finally {
if (response != null) {
response.close();
}
webServiceClient.destroy();
}
} }
@VisibleForTesting @VisibleForTesting

View File

@ -58,11 +58,18 @@ public static JSONObject getNodeInfoFromRMWebService(Configuration conf,
WebResource webResource = webServiceClient.resource(webAppAddress); WebResource webResource = webServiceClient.resource(webAppAddress);
ClientResponse response = webResource.path("ws").path("v1") ClientResponse response = null;
.path("cluster").path("nodes") try {
.path(nodeId).accept(MediaType.APPLICATION_JSON) response = webResource.path("ws").path("v1").path("cluster")
.path("nodes").path(nodeId).accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class); .get(ClientResponse.class);
return response.getEntity(JSONObject.class); return response.getEntity(JSONObject.class);
} finally {
if (response != null) {
response.close();
}
webServiceClient.destroy();
}
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")