Skip to content

Return friendly error when AMQP 1.0 receiver has no source (backport #15147)#15151

Merged
ansd merged 1 commit intov4.2.xfrom
mergify/bp/v4.2.x/pr-15147
Dec 17, 2025
Merged

Return friendly error when AMQP 1.0 receiver has no source (backport #15147)#15151
ansd merged 1 commit intov4.2.xfrom
mergify/bp/v4.2.x/pr-15147

Conversation

@mergify
Copy link

@mergify mergify bot commented Dec 17, 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


This is an automatic backport of pull request #15147 done by Mergify.

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)
@ansd ansd merged commit d7a7a25 into v4.2.x Dec 17, 2025
576 of 577 checks passed
@ansd ansd deleted the mergify/bp/v4.2.x/pr-15147 branch December 17, 2025 09:17
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.

2 participants