You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/09/27 19:54:30 UTC

[GitHub] [pulsar] eolivelli commented on a change in pull request #12181: Limit the semaphore count of the producer to prevent int overflow

eolivelli commented on a change in pull request #12181:
URL: https://github.com/apache/pulsar/pull/12181#discussion_r716997559



##########
File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
##########
@@ -1018,14 +1021,17 @@ private long getHighestSequenceId(OpSendMsg op) {
     }
 
     private void releaseSemaphoreForSendOp(OpSendMsg op) {
-        if (semaphore.isPresent()) {
-            semaphore.get().release(isBatchMessagingEnabled() ? op.numMessagesInBatch : 1);
-        }
+        semaphore.ifPresent(semaphore -> semaphore.release(
+                Math.min(
+                        maxPermits - semaphore.availablePermits(),

Review comment:
       I don't understand how we are dealing with concurrency here.
   When you capture the number of available permits another thread could have operated on the semaphore 




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org