Gateways: data race when setting first ping timer

This was introduced when fixing #2881. The call to setFirstPingTimer
needed to be done under the client's lock.

Moved setFirstPingTimer from a server receiver to a client receiver.
The only reason it was a server receiver is because we need the
server options, but c.srv is always set when invoking this function,
so we will get the server from c.srv in that function now.

Related to #2881

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2022-03-04 19:55:07 -07:00
parent 52e3b4b545
commit 85b3f8a7fd
5 changed files with 39 additions and 40 deletions

View File

@@ -1402,7 +1402,7 @@ func (c *client) processLeafNodeConnect(s *Server, arg []byte, lang string) erro
}
// Set the Ping timer
s.setFirstPingTimer(c)
c.setFirstPingTimer()
// If we received pub deny permissions from the other end, merge with existing ones.
c.mergeDenyPermissions(pub, proto.DenyPub)
@@ -2526,7 +2526,7 @@ func (s *Server) leafNodeFinishConnectProcess(c *client) {
c.mu.Lock()
closed := c.isClosed()
if !closed {
s.setFirstPingTimer(c)
c.setFirstPingTimer()
}
c.mu.Unlock()
if closed {