poorbarcode commented on code in PR #23123:
URL: https://github.com/apache/pulsar/pull/23123#discussion_r1703485137


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java:
##########
@@ -3605,19 +3605,38 @@ public String clientSourceAddressAndPort() {
 
     @Override
     public CompletableFuture<Optional<Boolean>> checkConnectionLiveness() {
+        if (!isActive()) {
+            return CompletableFuture.completedFuture(Optional.of(false));
+        }
         if (connectionLivenessCheckTimeoutMillis > 0) {
             return 
NettyFutureUtil.toCompletableFuture(ctx.executor().submit(() -> {
+                if (!isActive()) {
+                    return 
CompletableFuture.completedFuture(Optional.of(false));
+                }
                 if (connectionCheckInProgress != null) {
                     return connectionCheckInProgress;
                 } else {
                     final CompletableFuture<Optional<Boolean>> 
finalConnectionCheckInProgress =
                             new CompletableFuture<>();
                     connectionCheckInProgress = finalConnectionCheckInProgress;
                     ctx.executor().schedule(() -> {
+                        if (!isActive()) {
+                            
finalConnectionCheckInProgress.complete(Optional.of(false));
+                            return;
+                        }
                         if (finalConnectionCheckInProgress == 
connectionCheckInProgress
                                 && !finalConnectionCheckInProgress.isDone()) {
                             log.warn("[{}] Connection check timed out. Closing 
connection.", this.toString());
                             ctx.close();
+                        } else if (finalConnectionCheckInProgress != 
connectionCheckInProgress){
+                            log.info("[{}] Connection check might be success, 
because the variable"
+                                    + " connectionCheckInProgress has been 
override by the following check.",
+                                    this.toString());
+                            
finalConnectionCheckInProgress.complete(Optional.of(true));

Review Comment:
   **Scenarios that changing `connectionCheckInProgress`**
   - `connectionCheckInProgress` will be changed to `null` after a successful 
`Ping & Pong`
   - `connectionCheckInProgress` will be set to a new future the next time 
`checkConnectionLiveness` when `connectionCheckInProgress` is null.
   
   Once `finalConnectionCheckInProgress` is not equal to 
`connectionCheckInProgress`, it means Scenario 1 occurred before. If `receiving 
Pong` and `scheduled task` are executing at the same time(since they will be 
executing at the same thread, the concurrency scenario can not occur, I will 
change the log-level to `ERROR`), and this log will be printed. see more 
details here: https://github.com/apache/pulsar/pull/23123#discussion_r1703477705



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to