1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

fix race condition in ActivityTimer

This commit is contained in:
Darien Raymond 2018-06-22 11:19:33 +02:00
parent 57d6808882
commit ef4542e778
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

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