Skip to content

Respond with basic.cancel-ok to the servers that support it - #2113

Merged
michaelklishin merged 5 commits into
mainfrom
mk-basic-cancel-ok-server-capability
Oct 6, 2026
Merged

michaelklishin merged 5 commits into
mainfrom
mk-basic-cancel-ok-server-capability

Conversation

@michaelklishin

@michaelklishin michaelklishin commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

If the server advertises basic.cancel-ok response support.

The background on this is this: starting with 4.3.0, a delivery acknowledgement timeout does not result in the channel being closed but rather a
basic.cancel sent to the client.

Between about 2011 and 2026, clients never had
the need to respond to such basic.cancel because it was originally a client-sent method
and with consumer cancel notifications (an AMQP 0-9-1 extension), the client-sent confirmation was never required or expected.

Unfortunately, RabbitMQ versions between 4.3.0
and 4.3.6 only clean up the consumer after
a basic.cancel-ok arrives but older versions
cannot handle basic.cancel-ok, hence the new
capability and the conditional confirmation.

The Server Part of the Changes

See rabbitmq/rabbitmq-server#17734 for what's being
changed on the server to restore compatibility with older clients.

@michaelklishin michaelklishin added this to the 6.0.0 milestone Oct 6, 2026
If the server advertises `basic.cancel-ok` response support.

The background on this is this: starting with `4.3.0`,
a delivery acknowledgement timeout does not result
in the channel being closed but rather a
`basic.cancel` sent to the client.

Between about 2011 and 2026, clients never had
the need to respond to such `basic.cancel` because
it was originally a client method.

Unfortunately, RabbitMQ versions between `4.3.0`
and `4.3.6` only clean up the consumer after
a `basic.cancel-ok` arrives but older versions
cannot handle `basic.cancel-ok`, hence the new
capability and the conditional confirmation.
@michaelklishin
michaelklishin force-pushed the mk-basic-cancel-ok-server-capability branch from a50d7af to 1c9a5c0 Compare October 6, 2026 01:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new test helper contains a race that can discard the simulated response and hang the test suite.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Adds capability-gated basic.cancel-ok responses for server-initiated consumer cancellation.

Changes:

  • Introduces server capability detection
  • Sends conditional cancellation acknowledgements
  • Adds capability and channel behavior tests
File Description
ServerCapability.java Defines advertised server capabilities
AMQConnection.java Detects server capability support
ChannelN.java Sends conditional basic.cancel-ok responses
AMQConnectionCapabilitiesTest.java Tests capability detection
ChannelNTest.java Tests cancellation response behavior

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +169 to +177
new Thread(() -> {
try {
Thread.sleep(15);
channel.handleCompleteInboundCommand(
new AMQCommand(new AMQImpl.Basic.ConsumeOk(consumerTag)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}).start();
@michaelklishin

Copy link
Copy Markdown
Contributor Author

Thank you, @acogoluegnes.

@michaelklishin
michaelklishin merged commit 68419a1 into main Oct 6, 2026
7 checks passed
@michaelklishin
michaelklishin deleted the mk-basic-cancel-ok-server-capability branch October 6, 2026 14:37
@michaelklishin

Copy link
Copy Markdown
Contributor Author

@Mergifyio backport v5.x

@mergify

mergify Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

backport v5.x

✅ Backports have been created

Details

Cherry-pick of 1c9a5c0 has failed:

On branch mergify/bp/v5.x/pr-2113
Your branch is up to date with 'origin/v5.x'.

You are currently cherry-picking commit 1c9a5c0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   src/main/java/com/rabbitmq/client/ServerCapability.java
	modified:   src/main/java/com/rabbitmq/client/impl/AMQConnection.java
	modified:   src/main/java/com/rabbitmq/client/impl/ChannelN.java
	new file:   src/test/java/com/rabbitmq/client/impl/AMQConnectionCapabilitiesTest.java

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/test/java/com/rabbitmq/client/test/ChannelNTest.java

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

michaelklishin added a commit that referenced this pull request Oct 6, 2026
Respond with `basic.cancel-ok` to the servers that support it (backport #2113)
suchitd added a commit to rabbitmq/rabbitmq-dotnet-client that referenced this pull request Oct 7, 2026
Starting with RabbitMQ 4.3.0, a delivery acknowledgement timeout
cancels the consumer with a broker-sent `Basic.Cancel` instead of
closing the channel, and the broker expects a `Basic.CancelOk` reply.
Brokers older than 4.3.0 do not accept the reply, so only reply to brokers that
advertise the `accept_consumer_cancel_ok` capability.

For more details, see rabbitmq/rabbitmq-server#17734 and
rabbitmq/rabbitmq-java-client#2113.
suchitd added a commit to rabbitmq/rabbitmq-dotnet-client that referenced this pull request Oct 7, 2026
Starting with RabbitMQ 4.3.0, a delivery acknowledgement timeout
cancels the consumer with a broker-sent `basic.cancel` instead of
closing the channel, and the broker expects a `basic.cancel-ok` reply.
Brokers older than 4.3.0 do not accept the reply, so only reply to brokers that
advertise the `accept_consumer_cancel_ok` capability.

For more details, see rabbitmq/rabbitmq-server#17734 and
rabbitmq/rabbitmq-java-client#2113.
JadeCong pushed a commit to CloudEngineHub/pika that referenced this pull request Oct 8, 2026
Starting with RabbitMQ 4.3.0, a delivery acknowledgement timeout
cancels the consumer with a broker-sent `Basic.Cancel` instead of
closing the channel, and the broker expects a `Basic.CancelOk` reply.
Brokers older than 4.3.0 do not accept the reply, so only reply to brokers that
advertise the `accept_consumer_cancel_ok` capability.

For more details, see rabbitmq/rabbitmq-server#17734 and
rabbitmq/rabbitmq-java-client#2113.
lukebakken pushed a commit to rabbitmq/rabbitmq-dotnet-client that referenced this pull request Oct 8, 2026
Starting with RabbitMQ 4.3.0, a delivery acknowledgement timeout
cancels the consumer with a broker-sent `basic.cancel` instead of
closing the channel, and the broker expects a `basic.cancel-ok` reply.
Brokers older than 4.3.0 do not accept the reply, so only reply to brokers that
advertise the `accept_consumer_cancel_ok` capability.

For more details, see rabbitmq/rabbitmq-server#17734 and
rabbitmq/rabbitmq-java-client#2113.
suchitd added a commit to rabbitmq/rabbitmq-dotnet-client that referenced this pull request Oct 12, 2026
Starting with RabbitMQ 4.3.0, a delivery acknowledgement timeout
cancels the consumer with a broker-sent `basic.cancel` instead of
closing the channel, and the broker expects a `basic.cancel-ok` reply.
Brokers older than 4.3.0 do not accept the reply, so only reply to brokers that
advertise the `accept_consumer_cancel_ok` capability.

For more details, see rabbitmq/rabbitmq-server#17734 and
rabbitmq/rabbitmq-java-client#2113.
suchitd added a commit to rabbitmq/rabbitmq-dotnet-client that referenced this pull request Oct 14, 2026
Starting with RabbitMQ 4.3.0, a delivery acknowledgement timeout
cancels the consumer with a broker-sent `basic.cancel` instead of
closing the channel, and the broker expects a `basic.cancel-ok` reply.
Brokers older than 4.3.0 do not accept the reply, so only reply to brokers that
advertise the `accept_consumer_cancel_ok` capability.

For more details, see rabbitmq/rabbitmq-server#17734 and
rabbitmq/rabbitmq-java-client#2113.
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