flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-7753) HandlerUtils should close the channel on error responses
Date Wed, 25 Jul 2018 21:34:00 GMT

    [ https://issues.apache.org/jira/browse/FLINK-7753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16556300#comment-16556300
] 

ASF GitHub Bot commented on FLINK-7753:
---------------------------------------

EronWright closed pull request #4765: [FLINK-7753] [flip-6] close REST channel on server error
URL: https://github.com/apache/flink/pull/4765
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/util/HandlerUtils.java
b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/util/HandlerUtils.java
index 0d7483aad3c..9de150d9dc4 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/util/HandlerUtils.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/util/HandlerUtils.java
@@ -74,7 +74,7 @@
 			sendErrorResponse(channelHandlerContext, httpRequest, new ErrorResponseBody("Internal
server error. Could not map response to JSON."), HttpResponseStatus.INTERNAL_SERVER_ERROR);
 			return;
 		}
-		sendResponse(channelHandlerContext, httpRequest, sw.toString(), statusCode);
+		sendResponse(channelHandlerContext, httpRequest, sw.toString(), statusCode, false);
 	}
 
 	/**
@@ -96,9 +96,9 @@ public static void sendErrorResponse(
 			mapper.writeValue(sw, errorMessage);
 		} catch (IOException e) {
 			// this should never happen
-			sendResponse(channelHandlerContext, httpRequest, "Internal server error. Could not map
error response to JSON.", HttpResponseStatus.INTERNAL_SERVER_ERROR);
+			sendResponse(channelHandlerContext, httpRequest, "Internal server error. Could not map
error response to JSON.", HttpResponseStatus.INTERNAL_SERVER_ERROR, true);
 		}
-		sendResponse(channelHandlerContext, httpRequest, sw.toString(), statusCode);
+		sendResponse(channelHandlerContext, httpRequest, sw.toString(), statusCode, isServerError(statusCode));
 	}
 
 	/**
@@ -108,19 +108,25 @@ public static void sendErrorResponse(
 	 * @param httpRequest originating http request
 	 * @param message which should be sent
 	 * @param statusCode of the message to send
+	 * @param forceClose indicates whether to forcibly close the connection after the response
is sent
 	 */
 	public static void sendResponse(
 			@Nonnull ChannelHandlerContext channelHandlerContext,
 			@Nonnull HttpRequest httpRequest,
 			@Nonnull String message,
-			@Nonnull HttpResponseStatus statusCode) {
+			@Nonnull HttpResponseStatus statusCode,
+			boolean forceClose) {
 		HttpResponse response = new DefaultHttpResponse(HTTP_1_1, statusCode);
 
 		response.headers().set(CONTENT_TYPE, "application/json");
 
-		if (HttpHeaders.isKeepAlive(httpRequest)) {
+		boolean keepAlive = !forceClose && HttpHeaders.isKeepAlive(httpRequest);
+		if (keepAlive) {
 			response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
 		}
+		else {
+			response.headers().set(CONNECTION, HttpHeaders.Values.CLOSE);
+		}
 
 		byte[] buf = message.getBytes(ConfigConstants.DEFAULT_CHARSET);
 		ByteBuf b = Unpooled.copiedBuffer(buf);
@@ -134,8 +140,12 @@ public static void sendResponse(
 		ChannelFuture lastContentFuture = channelHandlerContext.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
 
 		// close the connection, if no keep-alive is needed
-		if (!HttpHeaders.isKeepAlive(httpRequest)) {
+		if (!keepAlive) {
 			lastContentFuture.addListener(ChannelFutureListener.CLOSE);
 		}
 	}
+
+	private static boolean isServerError(@Nonnull HttpResponseStatus statusCode) {
+		return statusCode.code() >= 500 && statusCode.code() < 600;
+	}
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> HandlerUtils should close the channel on error responses
> --------------------------------------------------------
>
>                 Key: FLINK-7753
>                 URL: https://issues.apache.org/jira/browse/FLINK-7753
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Cluster Management, Mesos
>            Reporter: Eron Wright 
>            Assignee: Eron Wright 
>            Priority: Minor
>              Labels: pull-request-available
>
> Unexpected errors in the server pipeline correctly cause a 500 error response.   I suggest
that such responses also close the channel rather than allowing keep-alive.   This would be
a better security posture too since we don't know if the pipeline is corrupt following an
unexpected error.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message