Skip to content

Commit

Permalink
Cherry-picks for 2.10.16-RC.1 (#5445)
Browse files Browse the repository at this point in the history
Includes:

- #5437
- #5436
- #5444
  • Loading branch information
wallyqs committed May 17, 2024
2 parents 090b2e6 + 120055a commit f519a53
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
5 changes: 3 additions & 2 deletions conf/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (lx *lexer) emitString() {
} else {
finalString = lx.input[lx.start:lx.pos]
}

// Position of string in line where it started.
pos := lx.pos - lx.ilstart - len(finalString)
lx.items <- item{itemString, finalString, lx.line, pos}
Expand Down Expand Up @@ -332,12 +333,12 @@ func lexBlockStart(lx *lexer) stateFn {
lx.ignore()
return lx.pop()
case commentHashStart:
lx.push(lexBlockEnd)
lx.push(lexBlockStart)
return lexCommentStart
case commentSlashStart:
rn := lx.next()
if rn == commentSlashStart {
lx.push(lexBlockEnd)
lx.push(lexBlockStart)
return lexCommentStart
}
lx.backup()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/klauspost/compress v1.17.8
github.com/minio/highwayhash v1.0.2
github.com/nats-io/jwt/v2 v2.5.7
github.com/nats-io/nats.go v1.34.1
github.com/nats-io/nats.go v1.35.0
github.com/nats-io/nkeys v0.4.7
github.com/nats-io/nuid v1.0.1
go.uber.org/automaxprocs v1.5.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/nats-io/jwt/v2 v2.5.7 h1:j5lH1fUXCnJnY8SsQeB/a/z9Azgu2bYIDvtPVNdxe2c=
github.com/nats-io/jwt/v2 v2.5.7/go.mod h1:ZdWS1nZa6WMZfFwwgpEaqBV8EPGVgOTDHN/wTbz0Y5A=
github.com/nats-io/nats.go v1.34.1 h1:syWey5xaNHZgicYBemv0nohUPPmaLteiBEUT6Q5+F/4=
github.com/nats-io/nats.go v1.34.1/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
github.com/nats-io/nats.go v1.35.0 h1:XFNqNM7v5B+MQMKqVGAyHwYhyKb48jrenXNxIU20ULk=
github.com/nats-io/nats.go v1.35.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
Expand Down
33 changes: 33 additions & 0 deletions server/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4195,3 +4195,36 @@ func TestRouteNoLeakOnAuthTimeout(t *testing.T) {
t.Fatalf("Server should have no route connections, got %v", nc)
}
}

func TestRouteNoRaceOnClusterNameNegotiation(t *testing.T) {
// Running the test 5 times was consistently producing the race.
for i := 0; i < 5; i++ {
o1 := DefaultOptions()
// Set this cluster name as dynamic
o1.Cluster.Name = _EMPTY_
// Increase number of routes and pinned accounts to increase
// the number of processRouteConnect() happening in parallel
// to produce the race.
o1.Cluster.PoolSize = 5
o1.Cluster.PinnedAccounts = []string{"A", "B", "C", "D"}
o1.Accounts = []*Account{NewAccount("A"), NewAccount("B"), NewAccount("C"), NewAccount("D")}
s1 := RunServer(o1)
defer s1.Shutdown()

route := RoutesFromStr(fmt.Sprintf("nats://127.0.0.1:%d", o1.Cluster.Port))

o2 := DefaultOptions()
// Set this one as explicit. Use name that is likely to be "higher"
// than the dynamic one.
o2.Cluster.Name = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
o2.Cluster.PoolSize = 5
o2.Cluster.PinnedAccounts = []string{"A", "B", "C", "D"}
o2.Accounts = []*Account{NewAccount("A"), NewAccount("B"), NewAccount("C"), NewAccount("D")}
o2.Routes = route
s2 := RunServer(o2)
defer s2.Shutdown()
checkClusterFormed(t, s1, s2)
s2.Shutdown()
s1.Shutdown()
}
}
8 changes: 7 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,13 @@ func (s *Server) setClusterName(name string) {

// Return whether the cluster name is dynamic.
func (s *Server) isClusterNameDynamic() bool {
return s.getOpts().Cluster.Name == _EMPTY_
// We need to lock the whole "Cluster.Name" check and not use s.getOpts()
// because otherwise this could cause a data race with setting the name in
// route.go's processRouteConnect().
s.optsMu.RLock()
dynamic := s.opts.Cluster.Name == _EMPTY_
s.optsMu.RUnlock()
return dynamic
}

// Returns our configured serverName.
Expand Down

0 comments on commit f519a53

Please sign in to comment.