Repository navigation
Description
Before Creating the Bug Report
-
I found a bug, not just asking a question, which should be created in GitHub Discussions.
-
I have searched the GitHub Issues and GitHub Discussions of this repository and believe that this is not a duplicate.
-
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
- Create a
DefaultMQProducer, enable async backpressure, set the count limit to 10 and byte limit to 1 MiB. - In a client-only test, set a mocked
ExecutorServicewithsetAsyncSenderExecutorso accepted send tasks remain pending before transport. All acquisition paths, locks, semaphores and sender threads remain real. - 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. - 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. - Observe
InterruptedException, then read the available count permits and the size lock state. The count is 8 instead of 9, andReadWriteCASLock.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:
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.
Activity
[ISSUE apache#11645] Release async backpressure resources on interrup…
[ISSUE apache#11645] Test async backpressure interruption cleanup
[ISSUE apache#11645] Cover async backpressure timeout branches