BewareMyPower commented on a change in pull request #12259:
URL: https://github.com/apache/pulsar/pull/12259#discussion_r720108912



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
##########
@@ -912,16 +906,14 @@ protected WriteInEventLoopCallback 
newObject(Handle<WriteInEventLoopCallback> ha
     }
 
     private void clearPendingMessagesWhenClose() {
-        PulsarClientException ex = new 
PulsarClientException.AlreadyClosedException(
-                format("The producer %s of the topic %s was already closed 
when closing the producers",
-                        producerName, topic));
-        pendingMessages.forEach(msg -> {
-            
client.getMemoryLimitController().releaseMemory(msg.uncompressedSize);
-            msg.sendComplete(ex);
-            msg.cmd.release();
-            msg.recycle();
-        });
-        pendingMessages.clear();
+        setState(State.Closed);
+        synchronized (this) {

Review comment:
       I think it's okay to move `setState` outside the `synchronized` block. I 
think it's a problem of previous code. See `connectionOpened` and 
`connectionFailed`, `setState` is all called outside the `synchronized` block 
since it's an atomic operation. It's only called inside the `synchronized` 
block in `closeAsync`, which is unnecessary.




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