Skip to content

Conversation

@mergify
Copy link

@mergify mergify bot commented Mar 19, 2025

This commit fixes a bug in the Erlang AMQP 1.0 client.

Prior to this commit, to repro this bug:

  1. Send more than 2^16 messages to a queue.
  2. Grant more than a total of 2^16 link credit initially (on a single link
    or across multiple links) on a single session without any
    auto or manual link credit renewal.

The expectation is that thanks to sufficiently granted initial link-credit,
the client will receive all messages.
However, consumption stops after exactly 2^16-1 messages.

That's because the client lib was never sending a flow frame to the server.
So, after the client received all 2^16-1 messages (the initial
incoming-window set by the client), the server's remote-incoming-window
reached 0 causing the server to stop delivering messages.

The expectation is that the client lib automatically handles session
flow control without any manual involvement of the client app.

This commit implements this fix:

  • We keep the server's remote-incoming window always large by default as
    explained in https://www.rabbitmq.com/blog/2024/09/02/amqp-flow-control#incoming-window
  • Hence, the client lib sets its incoming-window to 100,000 initially.
  • The client lib tracks its incoming-window decrementing it by 1 for
    every transfer it received. (This wasn't done prior to this commit.)
  • Whenever this window shrinks below 50,000, the client sends a flow
    frame without any link information widening its incoming-window back to 100,000.
  • For test cases (maybe later for apps as well), there is a new function
    amqp10_client_session:flow/3, which allows for a test case to do manual
    session flow control. Its API is designed very similar to
    amqp10_client_session:flow_link/4 in that the test can optionally request
    the lib to auto widen the session window whenever it falls below a certain threshold.

This is an automatic backport of pull request #13574 done by [Mergify](https://mergify.com).

This commit fixes a bug in the Erlang AMQP 1.0 client.

Prior to this commit, to repro this bug:
1. Send more than 2^16 messages to a queue.
2. Grant more than a total of 2^16 link credit initially (on a single link
   or across multiple links) on a single session without any
   auto or manual link credit renewal.

The expectation is that thanks to sufficiently granted initial link-credit,
the client will receive all messages.
However, consumption stops after exactly 2^16-1 messages.

That's because the client lib was never sending a flow frame to the server.
So, after the client received all 2^16-1 messages (the initial
incoming-window set by the client), the server's remote-incoming-window
reached 0 causing the server to stop delivering messages.

The expectation is that the client lib automatically handles session
flow control without any manual involvement of the client app.

This commit implements this fix:
* We keep the server's remote-incoming window always large by default as
  explained in https://www.rabbitmq.com/blog/2024/09/02/amqp-flow-control#incoming-window
* Hence, the client lib sets its incoming-window to 100,000 initially.
* The client lib tracks its incoming-window decrementing it by 1 for
  every transfer it received. (This wasn't done prior to this commit.)
* Whenever this window shrinks below 50,000, the client sends a flow
  frame without any link information widening its incoming-window back to 100,000.
* For test cases (maybe later for apps as well), there is a new function
  `amqp10_client_session:flow/3`, which allows for a test case to do manual
  session flow control. Its API is designed very similar to
  `amqp10_client_session:flow_link/4` in that the test can optionally request
  the lib to auto widen the session window whenever it falls below a certain threshold.

(cherry picked from commit 32854e8)
@mergify mergify bot assigned ansd Mar 19, 2025
@michaelklishin michaelklishin merged commit 985ac4e into v4.1.x Mar 19, 2025
273 checks passed
@michaelklishin michaelklishin deleted the mergify/bp/v4.1.x/pr-13574 branch March 19, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants