[FLINK-4436] Unclosed DataOutputBuffer in Utils#setTokensFor() This closes #2402
Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/7e07bde8 Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/7e07bde8 Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/7e07bde8 Branch: refs/heads/flip-6 Commit: 7e07bde8c5b33e9985260416fdf75e15df102efa Parents: 66d4b87 Author: f7753 <mabiao...@gmail.com> Authored: Mon Aug 22 21:07:55 2016 +0800 Committer: zentol <ches...@apache.org> Committed: Thu Sep 8 12:04:25 2016 +0200 ---------------------------------------------------------------------- .../src/main/java/org/apache/flink/yarn/Utils.java | 15 ++++++++------- .../flink/yarn/YarnApplicationMasterRunner.java | 3 +-- 2 files changed, 9 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/7e07bde8/flink-yarn/src/main/java/org/apache/flink/yarn/Utils.java ---------------------------------------------------------------------- diff --git a/flink-yarn/src/main/java/org/apache/flink/yarn/Utils.java b/flink-yarn/src/main/java/org/apache/flink/yarn/Utils.java index d5bad2f..1496d61 100644 --- a/flink-yarn/src/main/java/org/apache/flink/yarn/Utils.java +++ b/flink-yarn/src/main/java/org/apache/flink/yarn/Utils.java @@ -155,15 +155,16 @@ public final class Utils { LOG.info("Adding user token " + id + " with " + token); credentials.addToken(id, token); } - DataOutputBuffer dob = new DataOutputBuffer(); - credentials.writeTokenStorageToStream(dob); + try (DataOutputBuffer dob = new DataOutputBuffer()) { + credentials.writeTokenStorageToStream(dob); - if(LOG.isDebugEnabled()) { - LOG.debug("Wrote tokens. Credentials buffer length: " + dob.getLength()); - } + if(LOG.isDebugEnabled()) { + LOG.debug("Wrote tokens. Credentials buffer length: " + dob.getLength()); + } - ByteBuffer securityTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength()); - amContainer.setTokens(securityTokens); + ByteBuffer securityTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength()); + amContainer.setTokens(securityTokens); + } } /** http://git-wip-us.apache.org/repos/asf/flink/blob/7e07bde8/flink-yarn/src/main/java/org/apache/flink/yarn/YarnApplicationMasterRunner.java ---------------------------------------------------------------------- diff --git a/flink-yarn/src/main/java/org/apache/flink/yarn/YarnApplicationMasterRunner.java b/flink-yarn/src/main/java/org/apache/flink/yarn/YarnApplicationMasterRunner.java index 4637b97..7453344 100644 --- a/flink-yarn/src/main/java/org/apache/flink/yarn/YarnApplicationMasterRunner.java +++ b/flink-yarn/src/main/java/org/apache/flink/yarn/YarnApplicationMasterRunner.java @@ -599,10 +599,9 @@ public class YarnApplicationMasterRunner { ctx.setEnvironment(containerEnv); - try { + try (DataOutputBuffer dob = new DataOutputBuffer()) { UserGroupInformation user = UserGroupInformation.getCurrentUser(); Credentials credentials = user.getCredentials(); - DataOutputBuffer dob = new DataOutputBuffer(); credentials.writeTokenStorageToStream(dob); ByteBuffer securityTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength()); ctx.setTokens(securityTokens);