Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data race when updating leader #6150

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

MauriceVanVeen
Copy link
Member

Should solve this data race, where rn.updateLeader(noLeader) was called without holding the lock.

==================
WARNING: DATA RACE
Write at 0x00c0011d6da8 by goroutine 238071:
  github.com/nats-io/nats-server/v2/server.(*raft).updateLeader()
      /home/travis/build/nats-io/nats-server/server/raft.go:3212 +0x1fa
  github.com/nats-io/nats-server/v2/server.TestJetStreamClusterDesyncAfterErrorDuringCatchup.func2()
      /home/travis/build/nats-io/nats-server/server/jetstream_cluster_4_test.go:3970 +0x1f2
  github.com/nats-io/nats-server/v2/server.TestJetStreamClusterDesyncAfterErrorDuringCatchup.func3()
      /home/travis/build/nats-io/nats-server/server/jetstream_cluster_4_test.go:4046 +0xc56
  testing.tRunner()
      /home/travis/sdk/go1.23.3/src/testing/testing.go:1690 +0x226
  testing.(*T).Run.gowrap1()
      /home/travis/sdk/go1.23.3/src/testing/testing.go:1743 +0x44
Previous read at 0x00c0011d6da8 by goroutine 238374:
  github.com/nats-io/nats-server/v2/server.(*raft).processAppendEntry()
      /home/travis/build/nats-io/nats-server/server/raft.go:3351 +0x124c
  github.com/nats-io/nats-server/v2/server.(*raft).processAppendEntries()
      /home/travis/build/nats-io/nats-server/server/raft.go:2029 +0x1f2
  github.com/nats-io/nats-server/v2/server.(*raft).runAsFollower()
      /home/travis/build/nats-io/nats-server/server/raft.go:2044 +0x446
  github.com/nats-io/nats-server/v2/server.(*raft).run()
      /home/travis/build/nats-io/nats-server/server/raft.go:1906 +0x557
  github.com/nats-io/nats-server/v2/server.(*raft).run-fm()
      <autogenerated>:1 +0x33
  github.com/nats-io/nats-server/v2/server.(*Server).startGoRoutine.func1()
      /home/travis/build/nats-io/nats-server/server/server.go:3885 +0x59

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

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner November 20, 2024 08:38
Copy link
Member

@wallyqs wallyqs left a comment

Choose a reason for hiding this comment

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

LGTM

@derekcollison derekcollison merged commit 1e017cd into main Nov 20, 2024
5 checks passed
@derekcollison derekcollison deleted the maurice/data-race-locked-update-leader branch November 20, 2024 10:06
neilalexander added a commit that referenced this pull request Nov 22, 2024
Includes:

- #6147
- #6150
- #6151
- #6153
- #6154
- #6146
- #6139
- #6152
- #6157
- #6161

Signed-off-by: Neil Twigg <neil@nats.io>
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.

3 participants