zentol commented on a change in pull request #13020:
URL: https://github.com/apache/flink/pull/13020#discussion_r462882826



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/AbstractHandler.java
##########
@@ -114,6 +115,21 @@ protected void respondAsLeader(ChannelHandlerContext ctx, 
RoutedRequest routedRe
                        log.trace("Received request " + httpRequest.uri() + 
'.');
                }
 
+               synchronized (this) {
+                       if (terminationFuture != null) {
+                               String errorMsg = "The handler instance for " + 
untypedResponseMessageHeaders.getTargetRestEndpointURL()
+                                       + " had already been closed";
+                               log.warn(errorMsg);
+                               HandlerUtils.sendErrorResponse(

Review comment:
       As of right now, should the NPE occur then all the user/dev sees is the 
same stack trace you got. That's not ideal.
   
   So instead, let's handle the case explicitly:
   ```
   private CompletableFuture<Void> handleException(Throwable throwable, 
ChannelHandlerContext ctx, HttpRequest httpRequest) {
                FlinkHttpObjectAggregator flinkHttpObjectAggregator = 
ctx.pipeline().get(FlinkHttpObjectAggregator.class);
                if (flinkHttpObjectAggregator == null) {
                        log.warn("The connection was closed unexpectedly.");
                        return CompletableFuture.completedFuture(null);
                }
                ...
   ```
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to