Skip to content

rpc, eth/filters: use non-blocking timer drain pattern #31141

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

Closed
wants to merge 1 commit into from

Conversation

JukLee0ira
Copy link
Contributor

Using a direct channel receive after Stop() may block in edge cases. A safer approach is to use select with a default case for timer cleanup.

PS: I noticed other instances in the code where Reset is used without draining the timer channel via Stop(). While this is fixed in Go 1.23+, it could cause undefined behavior in earlier versions. Would the team be open to addressing this for compatibility with pre-1.23 Go versions?I’d be happy to fix this in this PR if needed.

Ref: golang/go#37196

@fjl
Copy link
Contributor

fjl commented Feb 7, 2025

I don't think its necessary to address this at all. We used the pattern which is documented in package time. If this causes a hang, it's a bug in the Go runtime, and they fixed it in 1.23. We generally only support the latest two releases of Go, which are 1.22 and 1.23 right now. But 1.24 is coming up soon, and we will bump our baseline requirement to 1.23 when it is released.

Comment on lines +438 to +441
select {
case <-f.deadline.C:
default:
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could indeed deadlock in case there is wrong programming somewhere else. It might be more interesting to check other listeners of f.deadline and make sure they stop listening before the call f.deadline.Stop()? Same for the pingTimer changed in rpc/weboscket.go 🤔

@JukLee0ira JukLee0ira closed this Feb 10, 2025
@JukLee0ira JukLee0ira deleted the opt-timer-cleanup branch March 18, 2025 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants