Skip to content

ConnectionFactory Authmechanisms has incorrect sharing between instances #1370

Closed
@evolvedlight

Description

@evolvedlight

Describe the bug

if you connect to two RabbitMq instances, one with EXTERNAL auth, one plain, and change the Auth Mechanisms, the instances change each other.

Reproduction steps

  1. Create new project with rabbitmq client dependency (latest version)
    Paste the following:
ConnectionFactory factory = new ConnectionFactory();
factory.AuthMechanisms.Clear();
ConnectionFactory factory2 = new ConnectionFactory();
Console.WriteLine(factory2.AuthMechanisms.Count);

Expected behavior

I expect to have a single Plain Auth mechanism
Instead I have Zero auth mechanisms

Additional context

It's because the DefaultAuthMechanisms is referenced by reference rather than making a copy of it.
This bug is triggered by MassTransit: https://github.com/MassTransit/MassTransit/blob/15c44ca0c26e9dfcedbdf3e770621c5f3ceb6975/src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/RabbitMqAddressExtensions.cs#L65

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions