This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch 3.9.x
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit fa2357f6e87a52433198b9bd098ae9ad22b835c7
Author: Benoit TELLIER <[email protected]>
AuthorDate: Thu Oct 2 23:10:43 2025 +0200

    JAMES-3816 Correct ReactiveThrottler cancellation
    
    When cancelling a task that did not start being executed,
    and is polled off the queue while we are cancelling it, then
    it never gets decremented. Doing so we avoid a differential
    and ensured exactly once decrement.
    
    This version most importantly do not attempt to clean the physical
    queue. It simply lets the consumer discard cancelled tasks upon execution.
---
 .../org/apache/james/imapserver/netty/ReactiveThrottler.java   | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git 
a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ReactiveThrottler.java
 
b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ReactiveThrottler.java
index dad7f4e509..85f5bb5797 100644
--- 
a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ReactiveThrottler.java
+++ 
b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ReactiveThrottler.java
@@ -128,11 +128,11 @@ public class ReactiveThrottler {
             return one.asMono()
                 .doOnCancel(() -> {
                     cancelled.set(true);
-                    
Optional.ofNullable(taskHolder.disposable.get()).ifPresent(Disposable::dispose);
-                    boolean removed = queue.remove(taskHolder);
-                    if (removed) {
-                        concurrentRequests.decrementAndGet();
-                    }
+                    Optional.ofNullable(taskHolder.disposable.get())
+                        .ifPresentOrElse(Disposable::dispose,
+                            // If no Disposable set → task never started,
+                            // but still counted → must release the slot
+                            concurrentRequests::decrementAndGet);
                 });
         } else {
             concurrentRequests.decrementAndGet();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to