You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ch...@apache.org on 2015/09/05 09:19:33 UTC
flink git commit: [FLINK-2605] [runtime] Unclosed RandomAccessFile
may leak resource in StaticFileServerHandler
Repository: flink
Updated Branches:
refs/heads/master 3d528442f -> 491146281
[FLINK-2605] [runtime] Unclosed RandomAccessFile may leak resource in StaticFileServerHandler
This closes #1089.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/49114628
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/49114628
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/49114628
Branch: refs/heads/master
Commit: 4911462811309dd8b46574445b690a9cc38d2d87
Parents: 3d52844
Author: tedyu <yu...@gmail.com>
Authored: Thu Sep 3 07:11:32 2015 -0700
Committer: Chiwan Park <ch...@apache.org>
Committed: Sat Sep 5 16:17:50 2015 +0900
----------------------------------------------------------------------
.../files/StaticFileServerHandler.java | 37 +++++++++-----------
1 file changed, 17 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/49114628/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/files/StaticFileServerHandler.java
----------------------------------------------------------------------
diff --git a/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/files/StaticFileServerHandler.java b/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/files/StaticFileServerHandler.java
index e368ea9..b6642a2 100644
--- a/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/files/StaticFileServerHandler.java
+++ b/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/files/StaticFileServerHandler.java
@@ -165,29 +165,26 @@ public class StaticFileServerHandler extends SimpleChannelInboundHandler<Routed>
logger.debug("Responding with file '" + file.getAbsolutePath() + '\'');
}
- final RandomAccessFile raf;
- try {
- raf = new RandomAccessFile(file, "r");
- }
- catch (FileNotFoundException e) {
+ try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
+ long fileLength = raf.length();
+
+ HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
+ setContentTypeHeader(response, file);
+ setDateAndCacheHeaders(response, file);
+ if (HttpHeaders.isKeepAlive(request)) {
+ response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
+ }
+ HttpHeaders.setContentLength(response, fileLength);
+
+ // write the initial line and the header.
+ ctx.write(response);
+
+ // write the content.
+ ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise());
+ } catch (FileNotFoundException e) {
sendError(ctx, NOT_FOUND);
return;
}
- long fileLength = raf.length();
-
- HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
- setContentTypeHeader(response, file);
- setDateAndCacheHeaders(response, file);
- if (HttpHeaders.isKeepAlive(request)) {
- response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
- }
- HttpHeaders.setContentLength(response, fileLength);
-
- // write the initial line and the header.
- ctx.write(response);
-
- // write the content.
- ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise());
ChannelFuture lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
// close the connection, if no keep-alive is needed