BILLYisavailable opened a new issue, #11645:
URL: https://github.com/apache/rocketmq/issues/11645

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   
   ### Runtime platform environment
   
   macOS, ARM64. Deterministic client-side tests; the send executor is held 
before transport to reproduce exhausted admission limits without a broker.
   
   ### RocketMQ version
   
   develop, `19352a24679337276e041f67307c6d284dd48de9` (also the upstream HEAD 
checked before reporting).
   
   ### JDK Version
   
   OpenJDK 17.0.21.1; Maven 3.9.11.
   
   ### Describe the Bug
   
   With `setEnableBackpressureForAsyncMode(true)`, interrupting an async sender 
waiting for capacity leaks the corresponding backpressure read lock. If it is 
waiting for byte capacity, it also leaks the count permit already acquired.
   
   This can happen when an application cancels a request with 
`Future.cancel(true)` while a producer is backpressured. Each interrupted 
byte-capacity wait permanently reduces the producer's available send capacity. 
A later call to `setBackPressureForAsyncSendNum/Size` for the leaked lock spins 
indefinitely waiting for that reader, and blocks subsequent 
acquisitions/releases of that lock. Backpressure is opt-in; this report does 
not claim it is enabled by default.
   
   ### Steps to Reproduce
   
   1. Create a `DefaultMQProducer`, enable async backpressure, set the count 
limit to 10 and byte limit to 1 MiB.
   2. In a client-only test, set a mocked `ExecutorService` with 
`setAsyncSenderExecutor` so accepted send tasks remain pending before 
transport. All acquisition paths, locks, semaphores and sender threads remain 
real.
   3. Call `producer.send(new Message("TestTopic", new byte[1024 * 1024]), 
callback, 10000)`. It reserves one count permit and all byte permits. Available 
count permits are now 9.
   4. On another thread call `producer.send(new Message("TestTopic", new 
byte[1]), callback, 10000)`. Wait until the thread is waiting for capacity, 
interrupt it and join it.
   5. Observe `InterruptedException`, then read the available count permits and 
the size lock state. The count is **8 instead of 9**, and 
`ReadWriteCASLock.getWriteLock()` is false because the reader was not released.
   
   For the count-wait variant, queue ten 1-byte messages before interrupting 
the next sender. The count read lock remains held. The ordinary `send(message, 
callback)` overload also leaks resources while delivering the interruption to 
the user's callback.
   
   ### What Did You Expect to See?
   
   An interrupted send that was never submitted should release its locks and 
any acquired capacity. Existing exception/callback behavior should remain 
unchanged. Runtime limit updates should still be possible.
   
   ### What Did You See Instead?
   
   Two independently run regression cases failed on the unmodified commit:
   
   ```text
   count wait: backPressureForAsyncSendNumLock can be updated
     expected true, was false
   byte wait: available count permits
     expected 9, was 8
   byte wait: backPressureForAsyncSendSizeLock can be updated
     expected true, was false
   ```
   
   ### Additional Context
   
   `DefaultMQProducerImpl.executeAsyncMessageSend` releases both read locks 
only after interruptible `Semaphore.tryAcquire` returns normally. Its outer 
catch handles executor rejection, but not interruption. No send task is 
submitted on this path, so no completion callback can return the acquired count 
permit.
   
   The proposed fix uses `finally` for each read lock and returns acquired 
permits before rethrowing `InterruptedException`. Tests cover both wait sites, 
the default callback overload, and the existing byte-capacity timeout behavior. 
This is a client admission-control reproduction, not a live-broker load test.
   
   Searched issues, pull requests and discussions for backpressure and 
semaphoreAsyncSend. #8254 concerns accounting when resizing limits, not 
interrupted acquisition.


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