Skip to content

Return friendly error when AMQP 1.0 receiver has no source#15147

Merged
ansd merged 1 commit intorabbitmq:mainfrom
amazon-mq:lukebakken/rabbitmq-server-14300
Dec 17, 2025
Merged

Return friendly error when AMQP 1.0 receiver has no source#15147
ansd merged 1 commit intorabbitmq:mainfrom
amazon-mq:lukebakken/rabbitmq-server-14300

Conversation

@lukebakken
Copy link
Collaborator

@lukebakken lukebakken commented Dec 16, 2025

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.

Fixes #14300

@lukebakken lukebakken requested a review from ansd December 16, 2025 17:28
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
@lukebakken lukebakken force-pushed the lukebakken/rabbitmq-server-14300 branch from 805b6ea to 7d923ee Compare December 16, 2025 17:29
@lukebakken
Copy link
Collaborator Author

@ansd I added the code to reproduce the error here - https://github.com/lukebakken/rabbitmq-server-14300

Copy link
Member

@ansd ansd left a comment

Choose a reason for hiding this comment

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

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

@ansd ansd merged commit 8dfc64c into rabbitmq:main Dec 17, 2025
575 of 577 checks passed
ansd added a commit that referenced this pull request Dec 17, 2025
ansd added a commit that referenced this pull request Dec 17, 2025
Return friendly error when AMQP 1.0 receiver has no source (backport #15147)
ansd added a commit that referenced this pull request Dec 17, 2025
mergify bot pushed a commit that referenced this pull request Dec 17, 2025
(cherry picked from commit fef2449)
ansd added a commit that referenced this pull request Dec 17, 2025
@lukebakken lukebakken deleted the lukebakken/rabbitmq-server-14300 branch December 17, 2025 14:19
@lukebakken
Copy link
Collaborator Author

Thanks. I merged and did a follow-up commit in

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! 😸

@ansd
Copy link
Member

ansd commented Dec 17, 2025

feel free to change my code in a PR on my original branch

I don't have permissions to push to your branch? 🙃

@lukebakken
Copy link
Collaborator Author

lukebakken commented Dec 17, 2025

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 amazon-mq/upstream-to-rabbitmq-server is an organization-owned fork, and thus that setting isn't available 💩

michaelklishin pushed a commit that referenced this pull request Dec 19, 2025
michaelklishin pushed a commit that referenced this pull request Feb 24, 2026
michaelklishin pushed a commit that referenced this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants