michaeljmarshall commented on a change in pull request #13428:
URL: https://github.com/apache/pulsar/pull/13428#discussion_r773328796



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -292,24 +292,30 @@ public void channelInactive(ChannelHandlerContext ctx) 
throws Exception {
 
         // Connection is gone, close the producers immediately
         producers.forEach((__, producerFuture) -> {
+            // prevent race conditions in completing producers
+            if (!producerFuture.isDone()
+                    && producerFuture.completeExceptionally(new 
IllegalStateException("Connection closed."))) {
+                return;
+            }
             if (producerFuture.isDone() && 
!producerFuture.isCompletedExceptionally()) {
                 Producer producer = producerFuture.getNow(null);
                 producer.closeNow(true);
             }
         });
 
         consumers.forEach((__, consumerFuture) -> {
-            Consumer consumer;
-            if (consumerFuture.isDone() && 
!consumerFuture.isCompletedExceptionally()) {
-                consumer = consumerFuture.getNow(null);
-            } else {
+            // prevent race conditions in completing consumers
+            if (!consumerFuture.isDone()
+                    && consumerFuture.completeExceptionally(new 
IllegalStateException("Connection closed."))) {

Review comment:
       Same nit here.

##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -292,24 +292,30 @@ public void channelInactive(ChannelHandlerContext ctx) 
throws Exception {
 
         // Connection is gone, close the producers immediately
         producers.forEach((__, producerFuture) -> {
+            // prevent race conditions in completing producers
+            if (!producerFuture.isDone()
+                    && producerFuture.completeExceptionally(new 
IllegalStateException("Connection closed."))) {

Review comment:
       Nit. I don't think we need to call `!producerFuture.isDone()`. The logic 
is the same when removing the check.
   
   ```suggestion
               if (producerFuture.completeExceptionally(new 
IllegalStateException("Connection closed."))) {
   ```




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