Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Mux logging on Close #2901

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions internal/mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ type Config struct {

// Mux allows multiplexing
type Mux struct {
lock sync.RWMutex
nextConn net.Conn
endpoints map[*Endpoint]MatchFunc
bufferSize int
closedCh chan struct{}
lock sync.Mutex
endpoints map[*Endpoint]MatchFunc
isClosed bool

pendingPackets [][]byte

log logging.LeveledLogger
closedCh chan struct{}
log logging.LeveledLogger
}

// NewMux creates a new Mux
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
Loading