kylemeow commented on a change in pull request #11639: [FLINK-16626][runtime] 
Prevent REST handler from being closed more than once
URL: https://github.com/apache/flink/pull/11639#discussion_r404755577
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/AbstractHandler.java
 ##########
 @@ -221,7 +227,12 @@ private void finalizeRequestProcessing(FileUploads 
uploadedFiles) {
 
        @Override
        public final CompletableFuture<Void> closeAsync() {
-               return FutureUtils.composeAfterwards(closeHandlerAsync(), 
inFlightRequestTracker::awaitAsync);
+               if (isHandlerClosed.compareAndSet(false, true)) {
+                       return 
FutureUtils.composeAfterwards(closeHandlerAsync(), 
inFlightRequestTracker::awaitAsync);
+               } else {
+                       log.warn("The handler instance for {} had already been 
closed, but another attempt at closing it was made.", 
untypedResponseMessageHeaders.getTargetRestEndpointURL());
+                       return CompletableFuture.completedFuture(null);
 
 Review comment:
   > I don't think we should return a completed future if the handle has 
received "close" message. It is possible that the handle is still closing. 
Possibly we alter `inFlightRequestTracker::awaitAsync` to return the terminate 
future if it is closed, without deregister the phaser party.
   > 
   > cc @zentol @GJL
   
   Hi @TisonKun , thanks for your review. 
   
   My original thought was that a completed ComplatableFuture 
*CompletableFuture.completedFuture(null)* would indicate that this invocation 
has finished without any longer effect, as it has nothing to do with the 
previous call from the user's perspective.
   
   To my understanding, if the REST handler was previously requested to be 
closed, then the corresponding CompletableFuture would have already been sent 
to the user, and if that CompletedFuture is still not finished, 
org.apache.flink.runtime.rest.RestServerEndpoint#closeHandlersAsync would wait 
for its completion, so it would not cause the RestServerEndpoint to shutdown 
earlier.
   
   Or else maybe we could just throw an *Exception* if the handler is being 
closed more than once? This would make the design simpler.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to