YARN-7402. [GPG] Fix potential connection leak in GPGUtils. Contributed by Giovanni Matteo Fumarola.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/c5bf22dc Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/c5bf22dc Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/c5bf22dc Branch: refs/heads/YARN-7402 Commit: c5bf22dc13b5bbe57b45fe81dd2d912af3b87602 Parents: f5da8ca Author: Botong Huang <bot...@apache.org> Authored: Wed May 23 12:45:32 2018 -0700 Committer: Botong Huang <bot...@apache.org> Committed: Tue May 29 10:48:40 2018 -0700 ---------------------------------------------------------------------- .../server/globalpolicygenerator/GPGUtils.java | 31 +++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/c5bf22dc/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java index 429bec4..31cee1c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-globalpolicygenerator/src/main/java/org/apache/hadoop/yarn/server/globalpolicygenerator/GPGUtils.java @@ -18,21 +18,22 @@ package org.apache.hadoop.yarn.server.globalpolicygenerator; +import static javax.servlet.http.HttpServletResponse.SC_OK; + import java.util.HashMap; import java.util.Map; import java.util.Set; -import javax.servlet.http.HttpServletResponse; import javax.ws.rs.core.MediaType; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; -import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; -import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo; /** * GPGUtils contains utility functions for the GPG. @@ -53,15 +54,23 @@ public final class GPGUtils { T obj = null; WebResource webResource = client.resource(webAddr); - ClientResponse response = webResource.path("ws/v1/cluster").path(path) - .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); - if (response.getStatus() == HttpServletResponse.SC_OK) { - obj = response.getEntity(returnType); - } else { - throw new YarnRuntimeException("Bad response from remote web service: " - + response.getStatus()); + ClientResponse response = null; + try { + response = webResource.path("ws/v1/cluster").path(path) + .accept(MediaType.APPLICATION_XML).get(ClientResponse.class); + if (response.getStatus() == SC_OK) { + obj = response.getEntity(returnType); + } else { + throw new YarnRuntimeException( + "Bad response from remote web service: " + response.getStatus()); + } + return obj; + } finally { + if (response != null) { + response.close(); + } + client.destroy(); } - return obj; } /** --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org