Skip to content

Commit

Permalink
Fix Mux logging on Close
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Sep 10, 2024
1 parent 1a214d2 commit 28adb77
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Mux struct {
bufferSize int
lock sync.Mutex
endpoints map[*Endpoint]MatchFunc
isClosed bool

pendingPackets [][]byte

Expand Down Expand Up @@ -96,6 +97,7 @@ func (m *Mux) Close() error {

delete(m.endpoints, e)
}
m.isClosed = true
m.lock.Unlock()

err := m.nextConn.Close()
Expand Down Expand Up @@ -154,22 +156,21 @@ func (m *Mux) dispatch(buf []byte) error {
break
}
}
m.lock.Unlock()

if endpoint == nil {
m.lock.Lock()
defer m.lock.Unlock()

if len(m.pendingPackets) >= maxPendingPackets {
m.log.Warnf("Warning: mux: no endpoint for packet starting with %d, not adding to queue size(%d)", buf[0], len(m.pendingPackets))
} else {
m.log.Warnf("Warning: mux: no endpoint for packet starting with %d, adding to queue size(%d)", buf[0], len(m.pendingPackets))
m.pendingPackets = append(m.pendingPackets, append([]byte{}, buf...))
if !m.isClosed {
if len(m.pendingPackets) >= maxPendingPackets {
m.log.Warnf("Warning: mux: no endpoint for packet starting with %d, not adding to queue size(%d)", buf[0], len(m.pendingPackets))
} else {
m.log.Warnf("Warning: mux: no endpoint for packet starting with %d, adding to queue size(%d)", buf[0], len(m.pendingPackets))
m.pendingPackets = append(m.pendingPackets, append([]byte{}, buf...))
}
}

return nil
}

m.lock.Unlock()
_, err := endpoint.buffer.Write(buf)

// Expected when bytes are received faster than the endpoint can process them (#2152, #2180)
Expand Down

0 comments on commit 28adb77

Please sign in to comment.