diff --git a/peer/server.go b/peer/server.go index 5143c85..9cce245 100644 --- a/peer/server.go +++ b/peer/server.go @@ -84,13 +84,20 @@ func (s *Server) listenAndServe(listener net.Listener) { log.Error(err) } else { s.stop.Add(1) - go s.handleConnection(conn) + go func() { + s.stop.Done() + s.handleConnection(conn) + }() } } } func (s *Server) handleConnection(conn net.Conn) { - defer s.stop.Done() + defer func() { + if err := conn.Close(); err != nil { + log.Error("error closing client connection for peer server - ", err) + } + }() timeoutDuration := 5 * time.Second for { diff --git a/reflector/server.go b/reflector/server.go index 48cdaa1..9f473d6 100644 --- a/reflector/server.go +++ b/reflector/server.go @@ -74,13 +74,20 @@ func (s *Server) listenAndServe(listener net.Listener) { log.Error(err) } else { s.stop.Add(1) - go s.handleConn(conn) + go func() { + s.stop.Done() + s.handleConn(conn) + }() } } } func (s *Server) handleConn(conn net.Conn) { - defer s.stop.Done() + defer func() { + if err := conn.Close(); err != nil { + log.Error("error closing client connection for reflector server - ", err) + } + }() // TODO: connection should time out eventually err := s.doHandshake(conn) if err != nil {