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_r405287917
 
 

 ##########
 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 am not sure whether we need to add such logics here. Since the 
`closeAsync` is not designed to be called multiple times and also currently we 
do not have this behavior. We close the handler one by one in 
`RestEndpoint#closeHandlersAsync`.
   
   Hi @wangyang0918 , I believe that this code is to prevent future developer 
from accidentally reusing the same handlers multiple times. As you can see, the 
bug described in this JIRA ticket was caused by inappropriate reuse of one REST 
handler.

----------------------------------------------------------------
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


With regards,
Apache Git Services

Reply via email to