Skip to content

ARTEMIS-6370 AMQP large message delivery loop on short body - #6916

Open
agagliardi wants to merge 1 commit into
apache:mainfrom
agagliardi:ARTEMIS-6370-amqp-large-message-short-body-loop
Open

agagliardi wants to merge 1 commit into
apache:mainfrom
agagliardi:ARTEMIS-6370-amqp-large-message-short-body-loop

Conversation

@agagliardi

Copy link
Copy Markdown

Fixes an unrecoverable AMQP large message delivery loop. Details in
ARTEMIS-6370; the short version:

  • AMQPLargeMessageWriter fed readInto's end-of-file -1 into ByteBuf.writerIndex, raising
    IndexOutOfBoundsException: readerIndex: 0, writerIndex: -1; a 0 length read spun the loop instead.
  • The resulting delivery error removed the consumer and requeued the message, so every consumer that
    attached afterwards failed the same way — the queue stopped delivering until an operator failed the
    broker over.
  • A short body can never satisfy the recorded size, so this one condition now raises a dedicated
    ActiveMQAMQPLargeMessageBodyException and the sender dead-letters the message rather than retrying,
    mirroring the ConversionException branch already in reportDeliveryError. It uses
    ServerConsumer.reject so the reference leaves the delivering list before the link teardown, which
    would otherwise put the message back on the queue.
  • The link is still closed: a partial transfer may already be on the wire and SenderImpl.abort() is a
    no-op in proton-j 0.35.0.
  • Also null-guards AMQPSessionCallback.disconnect, which NPE'd on a protocol context that the preceding
    consumer close clears asynchronously — the same race as ARTEMIS-5598, at a call site it missed.

New codes: AMQ119301 (the exception) and AMQ111016 (WARN when the message is dead-lettered).

Tests

Three unit tests in AMQPLargeMessageWriterTest and a new end-to-end
AmqpTruncatedLargeMessageBodyTest; all of them fail without the production changes. With the writer
fix reverted, two of the unit tests fail with the exact exception from the field report and the third
hangs to its timeout, demonstrating the zero-read spin.

Claude Code on behalf of Antonio Gagliardi

🤖 Generated with Claude Code

An AMQP large message whose stored body is smaller than the body size
recorded for it put the broker into an unrecoverable retry loop. The
streaming loop in AMQPLargeMessageWriter passed the result of
LargeBodyReader.readInto straight into ByteBuf.writerIndex, so the -1
that a sequential file read returns at end of file raised an
IndexOutOfBoundsException naming a writerIndex of -1.

That reached ProtonServerSenderContext.reportDeliveryError, which
removed the consumer and handed the reference back to the queue, so
the next consumer to attach failed the same way and the queue logged
AMQ222151 indefinitely while delivering nothing. A zero length read
had the same cause and spun the loop instead of raising anything.

The writer now checks the read before it is used and raises a
dedicated ActiveMQAMQPLargeMessageBodyTooSmallException, and the
sender sends that one condition to the dead letter address rather
than retrying a delivery that can never complete. It goes through
ServerConsumer reject so the reference leaves the consumer's
delivering list before the link is torn down, because the teardown
would otherwise return the message to the queue and the loop would
survive. The link is still closed, as a partial transfer may already
be on the wire and proton-j cannot abort one.

AMQPSessionCallback.disconnect also dereferenced a protocol context
that the preceding consumer close clears on the queue executor, so
the teardown raised a NullPointerException of its own. It now checks
for null the way hasCredits in the same class already does.

Assisted-by: Claude Code (Opus 5) on behalf of Antonio Gagliardi
@agagliardi
agagliardi force-pushed the ARTEMIS-6370-amqp-large-message-short-body-loop branch from d6bbd0a to 8c8db7a Compare November 18, 2026 13:58
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