Skip to content

fix(broker): snapshot fetch meters before deferred Mark - #3563

Merged
dnwe merged 2 commits into
mainfrom
dnwe/race
May 21, 2026
Merged

dnwe merged 2 commits into
mainfrom
dnwe/race

Conversation

@dnwe

@dnwe dnwe commented May 19, 2026

Copy link
Copy Markdown
Collaborator

The deferred Mark in Broker.Fetch read b.fetchRate / b.brokerFetchRate without b.lock, racing with Broker.Open's inner goroutine reassigning them on reconnect. Snapshot both under the lock and Mark the locals.

Fixes #3017

The deferred Mark in Broker.Fetch read b.fetchRate / b.brokerFetchRate
without b.lock, racing with Broker.Open's inner goroutine reassigning
them on reconnect. Snapshot both under the lock and Mark the locals.

Fixes #3017

Signed-off-by: Dominic Evans <dominic.evans@uk.ibm.com>
@dnwe dnwe added the fix label May 19, 2026
Comment thread broker.go Resolved
Comment thread broker_test.go Resolved
- move the b.fetchRate / b.brokerFetchRate reads inside the defer body
  so the lock/snapshot is taken at the point of access
- use sync.WaitGroup.Go in the race-condition test (Go 1.22+)

Signed-off-by: Dominic Evans <dominic.evans@uk.ibm.com>
@dnwe

dnwe commented May 21, 2026

Copy link
Copy Markdown
Collaborator Author

@DCjanus thanks, good suggestions - I've applied both

@puellanivis puellanivis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@hindessm hindessm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Great input from @DCjanus.

@dnwe
dnwe merged commit ff06f3a into main May 21, 2026
18 checks passed
@dnwe
dnwe deleted the dnwe/race branch May 21, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data race on broker fetchRate metric

4 participants