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

tabish121 pushed a commit to branch 1.x
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/1.x by this push:
     new cb484d3a PROTON-3003 Notify senders when a link flow changes the 
session window
cb484d3a is described below

commit cb484d3aff08d57ccf35d303b1b7c75c1cdf3823
Author: Arnaud Cogoluègnes <[email protected]>
AuthorDate: Thu Nov 5 17:14:17 2026 +0100

    PROTON-3003 Notify senders when a link flow changes the session window
    
    Publishers sharing a session could stall and fail with "Timed out
    waiting for credit to send", even though they had link credit and the
    session window was open.
    
    ProtonSession notified the senders of a session window change only for
    flow frames without a handle. The session fields are carried by every
    flow frame, so a flow for one link can reopen the window: only that link
    re-evaluated its sendable state, the other senders stayed blocked.
    A broker that updates the session window in link flow frames triggers
    the issue as soon as several publishers use the same connection.
    
    The senders are now notified after link flows as well. A sender that is
    not locally open ignores the notification, as it already does for link
    flows, its state being computed when it opens.
    
    (cherry picked from commit a6cef0fbb37fcb476ea177926ab4d2d7692c6f8c)
---
 .../qpid/protonj2/engine/impl/ProtonSender.java    |  5 ++
 .../qpid/protonj2/engine/impl/ProtonSession.java   | 18 ++++---
 .../protonj2/engine/impl/ProtonSessionTest.java    | 57 ++++++++++++++++++++++
 3 files changed, 74 insertions(+), 6 deletions(-)

diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonSender.java 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonSender.java
index bde151a2..82c6d2e7 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonSender.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonSender.java
@@ -273,6 +273,11 @@ public class ProtonSender extends ProtonLink<Sender> 
implements Sender {
     }
 
     ProtonSender handleSessionCreditStateUpdate(ProtonSessionOutgoingWindow 
protonSessionOutgoingWindow) {
+        if (!isLocallyOpen()) {
+            // same as for link flows, the sendable state is computed when the 
link opens locally
+            return this;
+        }
+
         final boolean previousSendable = sendable;
 
         sendable = getCredit() > 0 && sessionWindow.isSendable();
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonSession.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonSession.java
index a0b536fb..a95e6960 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonSession.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonSession.java
@@ -561,12 +561,24 @@ public class ProtonSession extends 
ProtonEndpoint<Session> implements Session {
             }
 
             link.remoteFlow(flow);
+            // a link flow can also reopen the session window, the other 
senders must be notified
+            handleSessionWindowUpdate(previousSessionWritable);
         } else {
             handleSessionOnlyFlow(flow, previousSessionWritable);
         }
     }
 
     private void handleSessionOnlyFlow(Flow flow, boolean 
previousSessionWritable) {
+        handleSessionWindowUpdate(previousSessionWritable);
+
+        if (flow.getEcho()) {
+            // Auto respond to session level echo requests as there's not an 
event point at the
+            // moment that would otherwise allow a response.
+            writeFlow(null);
+        }
+    }
+
+    private void handleSessionWindowUpdate(boolean previousSessionWritable) {
         if (previousSessionWritable != outgoingWindow.isSendable()) {
             for (ProtonSender sender : senders()) {
                 sender.handleSessionCreditStateUpdate(outgoingWindow);
@@ -576,12 +588,6 @@ public class ProtonSession extends ProtonEndpoint<Session> 
implements Session {
                 }
             }
         }
-
-        if (flow.getEcho()) {
-            // Auto respond to session level echo requests as there's not an 
event point at the
-            // moment that would otherwise allow a response.
-            writeFlow(null);
-        }
     }
 
     void remoteTransfer(Transfer transfer, ProtonBuffer payload, int channel) {
diff --git 
a/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonSessionTest.java
 
b/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonSessionTest.java
index ede871b4..013e3d7c 100644
--- 
a/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonSessionTest.java
+++ 
b/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonSessionTest.java
@@ -2670,6 +2670,63 @@ public class ProtonSessionTest extends 
ProtonEngineTestSupport {
         assertNull(failure);
     }
 
+    @Test
+    public void 
testOtherSenderNotifiedWhenSessionRemoteWindowReopenedByLinkFlow() throws 
Exception {
+        Engine engine = EngineFactory.PROTON.createNonSaslEngine();
+        engine.errorHandler(result -> failure = result.failureCause());
+        Queue<Runnable> asyncIOCallbacks = new ArrayDeque<>();
+        ProtonTestConnector peer = createTestPeer(engine, asyncIOCallbacks);
+
+        final byte[] payload = new byte[] {0, 1, 2, 3, 4};
+        final DeliveryTagGenerator generator = 
ProtonDeliveryTagGenerator.BUILTIN.POOLED.createGenerator();
+
+        // remote session incoming-window of 1 transfer
+        peer.expectAMQPHeader().respondWithAMQPHeader();
+        peer.expectOpen().respond();
+        peer.expectBegin().respond().withIncomingWindow(1);
+        peer.expectAttach().respond();
+        
peer.remoteFlow().withHandle(0).withDeliveryCount(0).withLinkCredit(20).withNextIncomingId(0).withIncomingWindow(1).queue();
+        peer.expectAttach().respond();
+        
peer.remoteFlow().withHandle(1).withDeliveryCount(0).withLinkCredit(20).withNextIncomingId(0).withIncomingWindow(1).queue();
+
+        Connection connection = engine.start().open();
+        Session session = connection.session().open();
+        Sender sender1 = 
session.sender("test1").setDeliveryTagGenerator(generator).open();
+        Sender sender2 = 
session.sender("test2").setDeliveryTagGenerator(generator).open();
+
+        peer.waitForScriptToComplete();
+        asyncIOCallbacks.forEach(Runnable::run);
+        asyncIOCallbacks.clear();
+
+        final AtomicInteger sender1CreditStateUpdated = new AtomicInteger();
+        sender1.creditStateUpdateHandler(self -> 
sender1CreditStateUpdated.incrementAndGet());
+
+        assertTrue(sender1.isSendable());
+        assertTrue(sender2.isSendable());
+
+        // sender 1 uses up the remote session window: no sender can send
+        peer.expectTransfer().withHandle(0).withPayload(payload);
+        
sender1.next().writeBytes(ProtonBufferAllocator.defaultAllocator().copy(payload));
+        peer.waitForScriptToComplete();
+        asyncIOCallbacks.forEach(Runnable::run);
+        asyncIOCallbacks.clear();
+
+        assertFalse(sender1.isSendable());
+        assertFalse(sender2.isSendable());
+
+        // the remote reopens the session window in a flow for sender 2's link 
(handle 1)
+        
peer.remoteFlow().withHandle(1).withDeliveryCount(0).withLinkCredit(20).withNextIncomingId(1).withIncomingWindow(1).now();
+
+        assertTrue(sender2.isSendable());
+        // sender 1 has 19 credits and the session window is open again
+        assertEquals(19, sender1.getCredit());
+        assertTrue(sender1.isSendable(), "sender 1 should be sendable");
+        assertEquals(1, sender1CreditStateUpdated.get(), "sender 1 should have 
been notified");
+
+        peer.waitForScriptToComplete();
+        assertNull(failure);
+    }
+
     @Test
     public void 
testSingleSenderUpdatedWhenOutgoingWindowOpenedForTwoIfFirstConsumesSessionOutgoingWindow()
 throws Exception {
         Engine engine = EngineFactory.PROTON.createNonSaslEngine();


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

Reply via email to