Skip to content

Commit

Permalink
Fix race condition in clientHasMovedToDifferentAccount (#4561)
Browse files Browse the repository at this point in the history
Fixes #4560. The client lock needs to be held before accessing the
`c.opts`.

Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
neilalexander committed Sep 19, 2023
2 parents ecbfac8 + 01872d2 commit 271b648
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/reload.go
Expand Up @@ -2009,24 +2009,24 @@ func (s *Server) clientHasMovedToDifferentAccount(c *client) bool {
nu *NkeyUser
u *User
)
if c.opts.Nkey != "" {
c.mu.Lock()
defer c.mu.Unlock()
if c.opts.Nkey != _EMPTY_ {
if s.nkeys != nil {
nu = s.nkeys[c.opts.Nkey]
}
} else if c.opts.Username != "" {
} else if c.opts.Username != _EMPTY_ {
if s.users != nil {
u = s.users[c.opts.Username]
}
} else {
return false
}
// Get the current account name
c.mu.Lock()
var curAccName string
if c.acc != nil {
curAccName = c.acc.Name
}
c.mu.Unlock()
if nu != nil && nu.Account != nil {
return curAccName != nu.Account.Name
} else if u != nil && u.Account != nil {
Expand Down

0 comments on commit 271b648

Please sign in to comment.