flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [49/51] [abbrv] flink git commit: Revert "[FLINK-2605] [runtime] Unclosed RandomAccessFile may leak resource in StaticFileServerHandler"
Date Thu, 17 Sep 2015 18:20:21 GMT
Revert "[FLINK-2605] [runtime] Unclosed RandomAccessFile may leak resource in StaticFileServerHandler"

The change breaks the functionality by returning incorrect HTTP responses (length / contents
mismatch).


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/482d4373
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/482d4373
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/482d4373

Branch: refs/heads/master
Commit: 482d4373facbf2e24bc76eb04b2a5550434c91b8
Parents: 506ce61
Author: Stephan Ewen <sewen@apache.org>
Authored: Wed Sep 16 22:38:40 2015 +0200
Committer: Stephan Ewen <sewen@apache.org>
Committed: Thu Sep 17 14:21:53 2015 +0200

----------------------------------------------------------------------
 .../files/StaticFileServerHandler.java          | 37 +++++++++++---------
 1 file changed, 20 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/482d4373/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 b6642a2..e368ea9 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,26 +165,29 @@ public class StaticFileServerHandler extends SimpleChannelInboundHandler<Routed>
 			logger.debug("Responding with file '" + file.getAbsolutePath() + '\'');
 		}
 
-		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) {
+		final RandomAccessFile raf;
+		try {
+			raf = new RandomAccessFile(file, "r");
+		}
+		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


Mime
View raw message