1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 14:56:33 -04:00

fix crash on init timeout = 0

This commit is contained in:
Darien Raymond 2017-12-14 17:39:58 +01:00
parent bf1f099b51
commit bc9267846c
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -26,6 +26,13 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
}
func (t *ActivityTimer) run(ctx context.Context, cancel context.CancelFunc) {
defer cancel()
timeout := <-t.timeout
if timeout == 0 {
return
}
ticker := time.NewTicker(<-t.timeout)
defer func() {
ticker.Stop()
@ -38,7 +45,6 @@ func (t *ActivityTimer) run(ctx context.Context, cancel context.CancelFunc) {
return
case timeout := <-t.timeout:
if timeout == 0 {
cancel()
return
}
@ -51,7 +57,6 @@ func (t *ActivityTimer) run(ctx context.Context, cancel context.CancelFunc) {
case <-t.updated:
// Updated keep waiting.
default:
cancel()
return
}
}