[FIXED] Possible stall on shutdown with leafnode setup

If a leafnode connection is accepted but the server is shutdown
before the connection is fully registered, the shutdown would
stall because read and write loop go routine would not be
stopped.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2020-05-22 15:26:04 -06:00
parent 0e3c73192d
commit 8f05bc5c46
2 changed files with 60 additions and 0 deletions

View File

@@ -794,6 +794,14 @@ func (s *Server) createLeafNode(conn net.Conn, remote *leafNodeCfg) *client {
}
}
// Keep track in case server is shutdown before we can successfully register.
if !s.addToTempClients(c.cid, c) {
c.mu.Unlock()
c.setNoReconnect()
c.closeConnection(ServerShutdown)
return nil
}
// Spin up the read loop.
s.startGoRoutine(func() { c.readLoop() })
@@ -955,6 +963,7 @@ func (s *Server) addLeafNodeConnection(c *client) {
s.mu.Lock()
s.leafs[cid] = c
s.mu.Unlock()
s.removeFromTempClients(cid)
}
func (s *Server) removeLeafNodeConnection(c *client) {
@@ -964,6 +973,7 @@ func (s *Server) removeLeafNodeConnection(c *client) {
s.mu.Lock()
delete(s.leafs, cid)
s.mu.Unlock()
s.removeFromTempClients(cid)
}
type leafConnectInfo struct {