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

[FIXED] Hold JS lock when accessing stream assignment #6173

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

MauriceVanVeen
Copy link
Member

Fixes this data race:

WARNING: DATA RACE
Read at 0x00c0034a4720 by goroutine 19950:
  runtime.mapiterinit()
      /home/travis/sdk/go1.23.3/src/runtime/map.go:877 +0x0
  github.com/nats-io/nats-server/v2/server.TestJetStreamClusterMaxConsumersMultipleConcurrentRequests()
      /home/travis/build/nats-io/nats-server/server/jetstream_cluster_2_test.go:2080 +0xcc6
  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 write at 0x00c0034a4720 by goroutine 20101:
  runtime.mapassign_faststr()
      /home/travis/sdk/go1.23.3/src/runtime/map_faststr.go:223 +0x0
  github.com/nats-io/nats-server/v2/server.(*jetStream).processConsumerAssignment()
      /home/travis/build/nats-io/nats-server/server/jetstream_cluster.go:4281 +0x834
  github.com/nats-io/nats-server/v2/server.(*jetStream).applyMetaEntries()
      /home/travis/build/nats-io/nats-server/server/jetstream_cluster.go:2015 +0x78a
  github.com/nats-io/nats-server/v2/server.(*jetStream).monitorCluster()
      /home/travis/build/nats-io/nats-server/server/jetstream_cluster.go:1413 +0x1194
  github.com/nats-io/nats-server/v2/server.(*jetStream).monitorCluster-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

js.streamAssignment mentions the lock should be held. Also found some other places that didn't lock.

// Will lookup a stream assignment.
// Lock should be held.
func (js *jetStream) streamAssignment(account, stream string) (sa *streamAssignment) {

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 25, 2024 14:54
Copy link
Member

@derekcollison derekcollison 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 4978da5 into main Nov 25, 2024
5 checks passed
@derekcollison derekcollison deleted the maurice/stream-assignment-lock branch November 25, 2024 15:37
neilalexander added a commit that referenced this pull request Nov 26, 2024
Includes the following:

- #6169
- #6165
- #6173
- #6175
- #6176
- #6178

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.

2 participants