diff --git a/pkg/netceptor/netceptor.go b/pkg/netceptor/netceptor.go index f44961268..27839cf19 100644 --- a/pkg/netceptor/netceptor.go +++ b/pkg/netceptor/netceptor.go @@ -784,20 +784,20 @@ func (s *Netceptor) monitorConnectionAging() { for { select { case <-time.After(5 * time.Second): - timedOut := make([]context.CancelFunc, 0) + timedOut := make(map[string]context.CancelFunc, 0) s.connLock.RLock() - for i := range s.connections { - conn := s.connections[i] - conn.lastReceivedLock.RLock() - if time.Since(conn.lastReceivedData) > s.maxConnectionIdleTime { - timedOut = append(timedOut, s.connections[i].CancelFunc) + for conn := range s.connections { + connInfo := s.connections[conn] + connInfo.lastReceivedLock.RLock() + if time.Since(connInfo.lastReceivedData) > s.maxConnectionIdleTime { + timedOut[conn] = s.connections[conn].CancelFunc } - conn.lastReceivedLock.RUnlock() + connInfo.lastReceivedLock.RUnlock() } s.connLock.RUnlock() - for i := range timedOut { - s.Logger.Warning("Timing out connection, idle for the past %s\n", s.maxConnectionIdleTime) - timedOut[i]() + for conn := range timedOut { + s.Logger.Warning("Timing out connection %s, idle for the past %s\n", conn, s.maxConnectionIdleTime) + timedOut[conn]() } case <-s.context.Done(): return @@ -922,13 +922,13 @@ func (s *Netceptor) flood(message []byte, excludeConn string) { defer s.connLock.RUnlock() for conn, ci := range s.connections { if conn != excludeConn { - go func(ci *connInfo) { + go func(conn string, ci *connInfo) { select { case ci.WriteChan <- message: case <-ci.Context.Done(): - s.Logger.Debug("connInfo cancelled during flood write") + s.Logger.Debug("connInfo for connection %s cancelled during flood write", conn) } - }(ci) + }(conn, ci) } } }