Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto widen session incoming-window in AMQP 1.0 client #13574

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

ansd
Copy link
Member

@ansd ansd 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.

@ansd ansd self-assigned this Mar 19, 2025
@ansd ansd force-pushed the amqp-client-incoming-window branch 3 times, most recently from 5cd0031 to dff1b54 Compare March 19, 2025 16:25
@ansd ansd marked this pull request as ready for review March 19, 2025 16:25
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.
@ansd ansd force-pushed the amqp-client-incoming-window branch from dff1b54 to 32854e8 Compare March 19, 2025 16:29
@michaelklishin michaelklishin merged commit c886693 into main Mar 19, 2025
273 checks passed
@michaelklishin michaelklishin deleted the amqp-client-incoming-window branch March 19, 2025 17:20
michaelklishin added a commit that referenced this pull request Mar 19, 2025
Auto widen session incoming-window in AMQP 1.0 client (backport #13574)
@ansd ansd added this to the 4.1.0 milestone Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants