Return friendly error when AMQP 1.0 receiver has no source#15147
Return friendly error when AMQP 1.0 receiver has no source#15147ansd merged 1 commit intorabbitmq:mainfrom
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 rabbitmq#14300
805b6ea to
7d923ee
Compare
|
@ansd I added the code to reproduce the error here - https://github.com/lukebakken/rabbitmq-server-14300 |
There was a problem hiding this comment.
I added the code to reproduce the error here - https://github.com/lukebakken/rabbitmq-server-14300
Thank you.
Thanks. I merged and did a follow-up commit in #15152
Return friendly error when AMQP 1.0 receiver has no source (backport #15147)
(cherry picked from commit fef2449)
Any time you'd like to change something, feel free to change my code in a PR on my original branch. No need for a follow-up! 😸 |
I don't have permissions to push to your branch? 🙃 |
|
Huh, I thought that pretty much always was the case with PR branches. The next time I open one, I'll make sure that's the case. Thanks for letting me know. UPDATE: hm I bet |
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