mirror of https://github.com/v2ray/v2ray-core
fix race condition in ActivityTimer
parent
57d6808882
commit
ef4542e778
|
@ -56,18 +56,20 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkTask := &task.Periodic{
|
||||||
|
Interval: timeout,
|
||||||
|
Execute: t.check,
|
||||||
|
}
|
||||||
|
|
||||||
t.Lock()
|
t.Lock()
|
||||||
|
|
||||||
if t.checkTask != nil {
|
if t.checkTask != nil {
|
||||||
t.checkTask.Close() // nolint: errcheck
|
t.checkTask.Close() // nolint: errcheck
|
||||||
}
|
}
|
||||||
t.checkTask = &task.Periodic{
|
t.checkTask = checkTask
|
||||||
Interval: timeout,
|
|
||||||
Execute: t.check,
|
|
||||||
}
|
|
||||||
t.Unlock()
|
t.Unlock()
|
||||||
t.Update()
|
t.Update()
|
||||||
common.Must(t.checkTask.Start())
|
common.Must(checkTask.Start())
|
||||||
}
|
}
|
||||||
|
|
||||||
func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {
|
func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeout time.Duration) *ActivityTimer {
|
||||||
|
|
Loading…
Reference in New Issue