Return friendly error when AMQP 1.0 receiver has no source (backport #15147)#15151
Merged
Return friendly error when AMQP 1.0 receiver has no source (backport #15147)#15151
Conversation
When a client attaches an AMQP 1.0 receiver link without specifying a
source address, RabbitMQ crashes with a `function_clause` error and
returns an Erlang stack trace to the client. This makes it difficult for
developers to understand what went wrong.
Previously, the client received:
```
SessionError: function_clause
[{rabbit_amqp_session,ensure_source,
[undefined,false,<<...>>,<<...>>,
{user,<<...>>,[administrator],[...]},
<<...>>,<0.585.0>,[],[]],
[{file,"rabbit_amqp_session.erl"},{line,2665}]},
{rabbit_amqp_session,handle_attach,2,...},
...]
```
This change adds a new clause to `ensure_source/9` that catches the case
where the source is `undefined`. Instead of crashing, the function now
returns `{error, source_address_required}`, which `handle_attach/2` maps
to an `amqp:invalid-field` error with a clear message.
Now, the client receives:
```
LinkError: Attach refused: source_address_required
condition: 'amqp:invalid-field',
description: 'Attach refused: source_address_required'
```
The error condition `amqp:invalid-field` is appropriate here because the
client failed to provide a required field in the attach frame, not
because a resource was not found.
Also added a test for an `undefined` receiver address.
Fixes https://github.com/rabbitmq/rabbitmq-server/discussions/14300
(cherry picked from commit 7d923ee)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a client attaches an AMQP 1.0 receiver link without specifying a source address, RabbitMQ crashes with a
function_clauseerror and returns an Erlang stack trace to the client. This makes it difficult for developers to understand what went wrong.Previously, the client received:
This change adds a new clause to
ensure_source/9that catches the case where the source isundefined. Instead of crashing, the function now returns{error, source_address_required}, whichhandle_attach/2maps to anamqp:invalid-fielderror with a clear message.Now, the client receives:
The error condition
amqp:invalid-fieldis appropriate here because the client failed to provide a required field in the attach frame, not because a resource was not found.Fixes #14300
This is an automatic backport of pull request #15147 done by Mergify.