Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The timer cannot be triggered on time #39773

Closed
caleb-letsgo opened this issue Jun 23, 2020 · 3 comments
Closed

The timer cannot be triggered on time #39773

caleb-letsgo opened this issue Jun 23, 2020 · 3 comments

Comments

@caleb-letsgo
Copy link

@caleb-letsgo caleb-letsgo commented Jun 23, 2020

golang 1.14.4
Judging from the logs, the timer is triggered only occasionally.

func refreshInf(ctx context.Context) {
	defer func() {
		log.Info("stop")
		if infTimer != nil {
			infTimer.Stop()
			infTimer = nil
		}
	}()
	for {
		select {
		case <-ctx.Done():
			return
		case <-infTimer.C:
			if infTimer == nil {
				return
			}
			infTimer.Reset(infCycle)
			go func() {
				log.Info("do refresh")
				//...
			}()
		}
	}
}
`
@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 23, 2020

  case <-infTimer.C:
  	if infTimer == nil {

if infTimer is nil, this code would panic.

@mvdan
Copy link
Member

@mvdan mvdan commented Jun 23, 2020

Please fill the template and provide a full example.

@caleb-letsgo
Copy link
Author

@caleb-letsgo caleb-letsgo commented Jul 1, 2020

This is only true if the mobile device is on standby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.