server: fix the issue if connections leak
When the connection closed, it should delete the connection from server's connections map. Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
This commit is contained in:
parent
0be804eadb
commit
9ece5ae787
@ -209,6 +209,13 @@ func (s *Server) addConnection(c *serverConn) {
|
||||
s.connections[c] = struct{}{}
|
||||
}
|
||||
|
||||
func (s *Server) delConnection(c *serverConn) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
delete(s.connections, c)
|
||||
}
|
||||
|
||||
func (s *Server) closeIdleConns() bool {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
@ -313,6 +320,7 @@ func (c *serverConn) run(sctx context.Context) {
|
||||
defer c.conn.Close()
|
||||
defer cancel()
|
||||
defer close(done)
|
||||
defer c.server.delConnection(c)
|
||||
|
||||
go func(recvErr chan error) {
|
||||
defer close(recvErr)
|
||||
|
Loading…
Reference in New Issue
Block a user