mirror of https://github.com/v2ray/v2ray-core
fix crash on init timeout = 0
parent
bf1f099b51
commit
bc9267846c
|
@ -26,6 +26,13 @@ func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ActivityTimer) run(ctx context.Context, cancel context.CancelFunc) {
|
func (t *ActivityTimer) run(ctx context.Context, cancel context.CancelFunc) {
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
timeout := <-t.timeout
|
||||||
|
if timeout == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(<-t.timeout)
|
ticker := time.NewTicker(<-t.timeout)
|
||||||
defer func() {
|
defer func() {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
|
@ -38,7 +45,6 @@ func (t *ActivityTimer) run(ctx context.Context, cancel context.CancelFunc) {
|
||||||
return
|
return
|
||||||
case timeout := <-t.timeout:
|
case timeout := <-t.timeout:
|
||||||
if timeout == 0 {
|
if timeout == 0 {
|
||||||
cancel()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +57,6 @@ func (t *ActivityTimer) run(ctx context.Context, cancel context.CancelFunc) {
|
||||||
case <-t.updated:
|
case <-t.updated:
|
||||||
// Updated keep waiting.
|
// Updated keep waiting.
|
||||||
default:
|
default:
|
||||||
cancel()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue