mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-24 06:19:08 +02:00
limit channel to 2 messages and drop outdated if needed
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/netbirdio/netbird/management/server/types"
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const channelBufferSize = 100
|
const channelBufferSize = 2
|
||||||
|
|
||||||
type UpdateMessage struct {
|
type UpdateMessage struct {
|
||||||
Update *proto.SyncResponse
|
Update *proto.SyncResponse
|
||||||
@@ -53,12 +53,19 @@ func (p *PeersUpdateManager) SendUpdate(ctx context.Context, peerID string, upda
|
|||||||
|
|
||||||
if channel, ok := p.peerChannels[peerID]; ok {
|
if channel, ok := p.peerChannels[peerID]; ok {
|
||||||
found = true
|
found = true
|
||||||
select {
|
for {
|
||||||
case channel <- update:
|
select {
|
||||||
log.WithContext(ctx).Debugf("update was sent to channel for peer %s", peerID)
|
case channel <- update:
|
||||||
default:
|
log.WithContext(ctx).Debugf("update was sent to channel for peer %s", peerID)
|
||||||
dropped = true
|
return
|
||||||
log.WithContext(ctx).Warnf("channel for peer %s is %d full or closed", peerID, len(channel))
|
default:
|
||||||
|
select {
|
||||||
|
case <-channel:
|
||||||
|
log.WithContext(ctx).Tracef("dropped oldest message from channel for peer %s", peerID)
|
||||||
|
default:
|
||||||
|
log.WithContext(ctx).Tracef("channel unexpectedly empty while trying to drop for peer %s", peerID)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.WithContext(ctx).Debugf("peer %s has no channel", peerID)
|
log.WithContext(ctx).Debugf("peer %s has no channel", peerID)
|
||||||
|
|||||||
Reference in New Issue
Block a user