mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 11:48:43 -07:00
Fix data race
When processing a connect request, there was a risk of race condition when the server was being shutdown. Capture fields that are checked under lock and lock when setting the route's remote ID. Resolves #255
This commit is contained in:
@@ -310,23 +310,28 @@ func (c *client) processConnect(arg []byte) error {
|
||||
c.mu.Lock()
|
||||
c.clearAuthTimer()
|
||||
c.last = time.Now()
|
||||
typ := c.typ
|
||||
r := c.route
|
||||
srv := c.srv
|
||||
c.mu.Unlock()
|
||||
|
||||
if err := json.Unmarshal(arg, &c.opts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.srv != nil {
|
||||
if srv != nil {
|
||||
// Check for Auth
|
||||
if ok := c.srv.checkAuth(c); !ok {
|
||||
if ok := srv.checkAuth(c); !ok {
|
||||
c.authViolation()
|
||||
return ErrAuthorization
|
||||
}
|
||||
}
|
||||
|
||||
// Grab connection name of remote route.
|
||||
if c.typ == ROUTER && c.route != nil {
|
||||
if typ == ROUTER && r != nil {
|
||||
c.mu.Lock()
|
||||
c.route.remoteID = c.opts.Name
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
if c.opts.Verbose {
|
||||
|
||||
Reference in New Issue
Block a user