mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-28 23:39:07 +01:00
[management] Skip inactivity expiration rescan on connect when a job is scheduled (#8287)
* [management] Skip inactivity expiration rescan when a job is scheduled Every SSO peer connect and disconnect cancelled the account's inactivity expiration job and re-armed it, loading every inactivity-enabled peer of the account each time. During a management deploy, when all peers reconnect, that is a full account scan per peer. A connecting peer cannot expire, and a disconnecting peer expires after every peer that was already disconnected, so neither can move the next run earlier. Connect and disconnect now leave an already scheduled job in place, as login expiration already does. Settings and per-peer toggle changes still cancel and reschedule, since they can move the run earlier. * [management] Keep inactivity rescan on disconnect A disconnect that lands while the inactivity job is finishing its last run saw the job as scheduled and skipped arming a new one; the scheduler then removed the job, leaving the disconnected peer without an inactivity timer. Only connect, where the peer cannot expire, now skips a scheduled job; disconnect cancels and re-arms as before. The test asserts on the synchronous Cancel call instead of sleeping.
This commit is contained in:
@@ -806,6 +806,21 @@ func (am *DefaultAccountManager) schedulePeerLoginExpiration(ctx context.Context
|
||||
}
|
||||
}
|
||||
|
||||
// schedulePeerInactivityExpiration arms the account's inactivity expiration job for a
|
||||
// connecting peer unless one is already scheduled: a connected peer cannot expire, so it
|
||||
// never moves the scheduled run earlier. Disconnects must not skip a running job, which may
|
||||
// be finishing its last run without seeing the newly disconnected peer.
|
||||
func (am *DefaultAccountManager) schedulePeerInactivityExpiration(ctx context.Context, accountID string) {
|
||||
if am.peerInactivityExpiry.IsSchedulerRunning(accountID) {
|
||||
log.WithContext(ctx).Tracef("peer inactivity expiration job for account %s is already scheduled", accountID)
|
||||
return
|
||||
}
|
||||
jobCtx := context.WithoutCancel(ctx)
|
||||
if nextRun, ok := am.getNextInactivePeerExpiration(ctx, accountID); ok {
|
||||
go am.peerInactivityExpiry.Schedule(jobCtx, nextRun, accountID, am.peerInactivityExpirationJob(jobCtx, accountID))
|
||||
}
|
||||
}
|
||||
|
||||
// peerInactivityExpirationJob marks login expired for all inactive peers and returns the minimum duration in which the next peer of the account will expire by inactivity if found
|
||||
func (am *DefaultAccountManager) peerInactivityExpirationJob(ctx context.Context, accountID string) func() (time.Duration, bool) {
|
||||
return func() (time.Duration, bool) {
|
||||
|
||||
Reference in New Issue
Block a user