Skip to content

Commit

Permalink
Fix data race when updating leader (#6150)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
derekcollison authored Nov 20, 2024
2 parents d9454d3 + e62990d commit 1e017cd
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/jetstream_cluster_4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3967,7 +3967,9 @@ func TestJetStreamClusterDesyncAfterErrorDuringCatchup(t *testing.T) {
for _, n := range server.raftNodes {
rn := n.(*raft)
if rn.accName == "$G" {
rn.Lock()
rn.updateLeader(noLeader)
rn.Unlock()
}
}

Expand Down

0 comments on commit 1e017cd

Please sign in to comment.