Skip to content

Commit

Permalink
Pass name of connection to logs (#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
matoval authored Sep 14, 2023
1 parent 466cb25 commit a3fd0ca
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pkg/netceptor/netceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit a3fd0ca

Please sign in to comment.