Skip to content

fix(amqp091): close BrokerDetails.state and Test_Retry races#104

Merged
miotte merged 1 commit into
mainfrom
miotte-pr8
Jun 10, 2026
Merged

fix(amqp091): close BrokerDetails.state and Test_Retry races#104
miotte merged 1 commit into
mainfrom
miotte-pr8

Conversation

@miotte

@miotte miotte commented May 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #103

Convert BrokerDetails.state to atomic.Uint32 (dropping the now-redundant locking in connectionWatcher), remove the redundant bd.tlsConfig rewrite in getBrokerDetails, and move the Test_Retry Headers assignment ahead of the goroutine that sends the message.

…nect, and Test_connect_connecting_*

Three pre-existing races surfaced under -race in this package:

- BrokerDetails.state was a uint16 written under bd.Mutex by connect()
  and connectionWatcher() but read without the lock from WaitForConnect,
  queueSubscribe, Publish, and connect()'s own CONNECTING fast-path
  check.  Converted to atomic.Uint32 so all reads/writes synchronize,
  and dropped the now-redundant Lock()/Unlock() around state-only
  writes in connectionWatcher.
- getBrokerDetails() unconditionally reassigned bd.tlsConfig on every
  call, racing with concurrent reads of bd.tlsConfig in connect().  The
  assignment was redundant: BrokerDetails is constructed with
  tlsConfig: prov.tlsConfig and prov.tlsConfig is never reassigned
  after NewAMQP091Provider, so removing the write fixes the race
  without changing behavior.
- Test_Retry built an amqp091Message, started a goroutine that sent it
  on a channel, and only then mutated mm.Headers from the test
  goroutine.  Moved the Headers assignment ahead of the goroutine so
  the value is fully populated before it is sent.

Test_Retry, Test_WaitForConnect, Test_connect_connecting_connected,
Test_connect_connecting_closed, and Test_connect_connecting_disconnected
now pass under \`go test -race\`.

Signed-off-by: Michael Otteni <MichaelGOtteni@gmail.com>
@miotte
miotte merged commit 3724443 into main Jun 10, 2026
7 checks passed
@miotte
miotte deleted the miotte-pr8 branch June 10, 2026 13:44
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.

Races in BrokerDetails.state, getBrokerDetails tlsConfig write, and Test_Retry message setup

3 participants