0
0
mirror of https://github.com/XTLS/Xray-core.git synced 2025-08-22 14:38:34 +00:00

Timer: prevent creating redundant check task

This commit is contained in:
patterniha 2025-08-22 09:12:10 +03:30
parent 33272a0499
commit eba1f7258e

View File

@ -56,20 +56,22 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
return
}
t.Lock()
defer t.Unlock()
if t.onTimeout == nil {
return
}
checkTask := &task.Periodic{
Interval: timeout,
Execute: t.check,
}
t.Lock()
if t.checkTask != nil {
t.checkTask.Close()
}
t.checkTask = checkTask
t.Update()
common.Must(checkTask.Start())
t.Unlock()
}
func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {