Skip to content

[FIXED] Mirror consumer data race#7395

Merged
neilalexander merged 1 commit intomainfrom
maurice/mirror-race
Oct 6, 2025
Merged

[FIXED] Mirror consumer data race#7395
neilalexander merged 1 commit intomainfrom
maurice/mirror-race

Conversation

@MauriceVanVeen
Copy link
Copy Markdown
Member

Fixes a data race with mirror.wg.Wait(), while the lock is not held.

WARNING: DATA RACE
Read at 0x00c000cf60a0 by goroutine 834:
  runtime.raceread()
      <autogenerated>:1 +0x1e
  github.com/nats-io/nats-server/v2/server.(*stream).setupMirrorConsumer.func7()
      server/stream.go:3372 +0xfe4
Previous write at 0x00c000cf60a0 by goroutine 756:
  runtime.racewrite()
      <autogenerated>:1 +0x1e
  github.com/nats-io/nats-server/v2/server.(*stream).setupMirrorConsumer.func7()
      server/stream.go:3304 +0x139

Signed-off-by: Maurice van Veen github@mauricevanveen.com

@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner October 6, 2025 09:10
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
Copy link
Copy Markdown
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

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

LGTM

@neilalexander neilalexander merged commit e680c1a into main Oct 6, 2025
69 of 70 checks passed
@neilalexander neilalexander deleted the maurice/mirror-race branch October 6, 2025 11:29
neilalexander added a commit that referenced this pull request Oct 6, 2025
Includes the following:

* #7395
* #7396

Signed-off-by: Neil Twigg <neil@nats.io>
neilalexander added a commit that referenced this pull request Oct 28, 2025
Includes the following:

- #7380
- #7384
- #7385
- #7388
- #7395
- #7400
- #7399
- #7401
- #7402
- #7423
- #7424
- #7411
- #7428
- #7429
- #7431
- #7435
- #7433
- #7443
- #7455
- #7465
- #7466
- #7460
- #7484
- #7479

Signed-off-by: Neil Twigg <neil@nats.io>
neilalexander added a commit that referenced this pull request Jan 12, 2026
Follow-up to #7395, since
Antithesis still manages to reproduce the data race. Instead of
capturing the mirror's `WaitGroup` outside the goroutine, let's capture
it in the goroutine itself which allows to check the mirror config
hasn't been removed in the meantime (for example due to a leader change
and this server not being leader anymore).

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
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