From eba1f7258e6e56cc2d47bb1891d17c2c173ba51c Mon Sep 17 00:00:00 2001 From: patterniha <71074308+patterniha@users.noreply.github.com> Date: Fri, 22 Aug 2025 09:12:10 +0330 Subject: [PATCH] Timer: prevent creating redundant check task --- common/signal/timer.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/signal/timer.go b/common/signal/timer.go index ece9f496..da108f2c 100644 --- a/common/signal/timer.go +++ b/common/signal/timer.go @@ -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 {