use peer.Status.LastSeen field to detect stale peer.Status.Connected values

Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
Dmitri Dolguikh
2026-08-20 16:06:50 +02:00
parent a144e8c144
commit cf4b9f8333
6 changed files with 39 additions and 0 deletions
@@ -423,6 +423,7 @@ func (s *Server) handleUpdates(ctx context.Context, accountID string, peerKey wg
// Create a debouncer for this peer connection
debouncer := NewUpdateDebouncer(1000 * time.Millisecond)
defer debouncer.Stop()
ticker := time.NewTicker(1 * time.Second)
for {
select {
@@ -448,6 +449,8 @@ func (s *Server) handleUpdates(ctx context.Context, accountID string, peerKey wg
}
}
s.accountManager.RefreshPeerLastSeen(ctx, accountID, peer.ID)
// Timer expired - quiet period reached, send pending updates if any
case <-debouncer.TimerChannel():
pendingUpdates := debouncer.GetPendingUpdates()
@@ -462,6 +465,11 @@ func (s *Server) handleUpdates(ctx context.Context, accountID string, peerKey wg
}
}
s.accountManager.RefreshPeerLastSeen(ctx, accountID, peer.ID)
case <-ticker.C:
s.accountManager.RefreshPeerLastSeen(ctx, accountID, peer.ID)
// condition when client <-> server connection has been terminated
case <-srv.Context().Done():
// happens when connection drops, e.g. client disconnects