Skip to content

Do not drop frames when a Netty frame write is interrupted (backport #2175) - #2176

Merged
acogoluegnes merged 2 commits into
v5.xfrom
mergify/bp/v5.x/pr-2175
Nov 12, 2026
Merged

acogoluegnes merged 2 commits into
v5.xfrom
mergify/bp/v5.x/pr-2175

Conversation

@mergify

@mergify mergify Bot commented Nov 12, 2026

Copy link
Copy Markdown

With Netty IO, writeFrame waits for the channel to become writable when it is not. If the thread is interrupted during this wait, the frame is silently dropped and basicPublish returns as if the message had been sent. If other frames of the same command were already written, the broker closes the connection with UNEXPECTED_FRAME.

This PR keeps waiting when the thread is interrupted and restores the interrupt flag afterwards. The enqueuing timeout still bounds the wait. The client already handles interrupts this way in BlockingCell.uninterruptibleGet.

As a trade-off, an interrupted thread can block for up to the enqueuing timeout. Throwing InterruptedIOException instead would not keep the connection, because the earlier frames of the command would already be on the wire.

I tested this against RabbitMQ 4.4.0 running in Docker on Java 8 and 21, by pausing the broker and interrupting a publisher. Before the change, messages were lost and the connection was closed. After the change, all messages were queued and the connection stayed open.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (correction or otherwise)
  • Cosmetics (whitespace, appearance)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

ultramancode and others added 2 commits November 12, 2026 17:41
With Netty IO, writeFrame waits for a non-writable channel to become
writable before writing the frame. If the thread was interrupted while
waiting, the frame was silently dropped. basicPublish returned as if
the message had been sent, but it never reached the broker. When other
frames of the same command had already been written, the broker
received an incomplete command and closed the connection with
UNEXPECTED_FRAME.

writeFrame now keeps waiting when the thread is interrupted and
restores the interrupt flag afterwards. The enqueuing timeout still
bounds the wait, so an interrupted thread can block for up to that
timeout before the frame is written or the write fails.

Signed-off-by: Taewoong Kim <ktw2172@gmail.com>
(cherry picked from commit 21bb8c4)
A thread waiting in writeFrame for a non-writable channel to become
writable was released only by a writability change. Netty does not
fire that event when the channel closes, so the thread stayed blocked
until the enqueuing timeout elapsed. Now that the wait can no longer
be interrupted, nothing could cut it short.

The writability latch is now counted down when the channel becomes
inactive. writeFrame then fails with an IOException instead of
writing to a closed channel.

(cherry picked from commit 20c246a)
@acogoluegnes acogoluegnes added this to the 5.38.0 milestone Nov 12, 2026
@acogoluegnes
acogoluegnes merged commit 299dff6 into v5.x Nov 12, 2026
4 of 6 checks passed
@acogoluegnes
acogoluegnes deleted the mergify/bp/v5.x/pr-2175 branch November 12, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants