Skip to content

Conversation

Copy link

Copilot AI commented Aug 25, 2025

Problem

The AMQP09 output would panic with "assignment to entry in nil map" when configured with exchange_declare.arguments. This occurred because the exchangeDeclareArgs field was never initialized before attempting to assign values to it.

output:
  amqp_0_9:
    urls:
      - amqp://guest:guest@localhost:5672/
    exchange: my-exchange
    exchange_declare:
      enabled: true
      type: direct
      durable: true
      arguments:
        alternate-exchange: my-ae
        x-message-ttl: 60000

The above configuration would cause a panic at runtime when the code tried to execute:

a.exchangeDeclareArgs[key] = value  // panic: assignment to entry in nil map

Solution

Added a length check before initializing the exchangeDeclareArgs map. The map is now only initialized when there are actually arguments to set:

if len(args) > 0 {
    a.exchangeDeclareArgs = make(amqp.Table)
    for key, value := range args {
        a.exchangeDeclareArgs[key] = value
    }
}

This preserves the original behavior where exchangeDeclareArgs remains nil when no arguments are provided (which is valid for AMQP exchange declarations), while properly initializing the map when arguments exist.

Testing

Added comprehensive unit tests to cover both scenarios:

  • Configuration with exchange arguments (previously panicked, now works)
  • Configuration without exchange arguments (preserves original nil behavior)

All existing integration tests continue to pass, ensuring no regression.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-authored-by: mmatczuk <1617930+mmatczuk@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue #3576 Aug 25, 2025
Copilot AI requested a review from mmatczuk August 25, 2025 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants