zentol commented on a change in pull request #6785: [FLINK-10309][rest] Before
shutting down cluster, wait for asynchronous operations
URL: https://github.com/apache/flink/pull/6785#discussion_r223364545
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/AbstractRestHandler.java
##########
@@ -75,19 +82,19 @@ protected AbstractRestHandler(
@Override
protected CompletableFuture<Void>
respondToRequest(ChannelHandlerContext ctx, HttpRequest httpRequest,
HandlerRequest<R, M> handlerRequest, T gateway) {
- CompletableFuture<P> response;
+ final CompletableFuture<P> response =
handleRequestInternal(handlerRequest, gateway);
- try {
- response = handleRequest(handlerRequest, gateway);
- } catch (RestHandlerException e) {
- response = FutureUtils.completedExceptionally(e);
- }
+ return response.whenCompleteAsync((P resp, Throwable throwable)
-> {
+ inFlightRequestTracker.deregisterRequest();
- return response.whenComplete((P resp, Throwable throwable) -> {
- Tuple2<ResponseBody, HttpResponseStatus> r = throwable
!= null ?
- errorResponse(throwable) : Tuple2.of(resp,
messageHeaders.getResponseStatusCode());
- HandlerUtils.sendResponse(ctx, httpRequest, r.f0, r.f1,
responseHeaders);
- }).thenApply(ignored -> null);
+ Tuple2<ResponseBody, HttpResponseStatus> r =
throwable != null ?
+ errorResponse(throwable) :
Tuple2.of(resp, messageHeaders.getResponseStatusCode());
+ HandlerUtils.sendResponse(ctx, httpRequest,
r.f0, r.f1, responseHeaders);
+ },
+ // send response from Netty's EventExecutor so that the
server channel
+ // does not close while we are responding to in-flight
requests
+ ctx.executor())
Review comment:
under what circumstances would the server channel close? Does it simply
close after a set or timeout or ...?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services