Skip to content

Actualize timers usage for go 1.23 - #74

Merged
jhump merged 4 commits into
bufbuild:mainfrom
glowfall:feature/actualize-timers
Apr 17, 2025
Merged

jhump merged 4 commits into
bufbuild:mainfrom
glowfall:feature/actualize-timers

Conversation

@glowfall

@glowfall glowfall commented Apr 15, 2025 •

Copy link
Copy Markdown
Contributor

Go 1.23 comes with behavior changes in timers, check out the full article: https://go.dev/wiki/Go123Timer

In short, three important changes:

  • timers do not need to be closed if not used anymore
  • you shouldn't bother about the state of timer before calling to Reset anymore
  • channels must not be emptied after the Stop() returned false

The last part is very important, since existing calls to <-timer.Chan() now could lead to deadlocks, see godoc:

// For a chan-based timer created with NewTimer(d), as of Go 1.23,
// any receive from t.C after Stop has returned is guaranteed to block
// rather than receive a stale time value from before the Stop;

https://github.com/golang/go/blob/065c1359e1bc3d6744a925339484592b13d713dd/src/time/sleep.go#L105C1-L109C47

@CLAassistant

CLAassistant commented Apr 15, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jhump jhump left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix!

@jhump
jhump enabled auto-merge (squash) April 16, 2025 14:47
@jhump
jhump disabled auto-merge April 16, 2025 15:05
@jhump

jhump commented Apr 16, 2025 •

Copy link
Copy Markdown
Member

@glowfall, the test faillures seem to be pretty consistent, not flaky. I'm not sure why, since it naively appears to be a timing race... But, in any event, I am pretty sure it's a bug in the test code. I think it will go away if you swap lines 219 and 220 in resolver_test.go. Hopefully you can reproduce locally and make sure the failure goes away before pushing a fix.

@glowfall

Copy link
Copy Markdown
Contributor Author

@glowfall, the test faillures seem to be pretty consistent, not flaky. I'm not sure why, since it naively appears to be a timing race... But, in any event, I am pretty sure it's a bug in the test code. I think it will go away if you swap lines 219 and 220 in resolver_test.go. Hopefully you can reproduce locally and make sure the failure goes away before pushing a fix.

Yep, looks like tests are broken now. And lines swapping does not seem to help.

My guess is that now clocktest implementation (https://github.com/jonboulle/clockwork) behaves differently, relying on the old timers behavior. See open issue: jonboulle/clockwork#98

I can offer some poor man's fix of tests on the fakeClock level, which just reproduces old behavior for the case duration==0: 8fe5aef
@jhump is it ok for you?

@jhump

jhump commented Apr 17, 2025

Copy link
Copy Markdown
Member

@jhump is it ok for you?

Yep, LGTM.

@jhump
jhump enabled auto-merge (squash) April 17, 2025 14:20
Comment thread internal/clocktest/clocktest.go Outdated
// information on why this is necessary.
func (f fakeClock) NewTimer(d time.Duration) internal.Timer {
return f.clockworkFakeClock.NewTimer(d)
t := f.clockworkFakeClock.NewTimer(d)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Name it timer to fix this lint issue.

BTW, you can run the linter locally before pushing via make lint.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, now it should be fixed

auto-merge was automatically disabled April 17, 2025 15:10

Head branch was pushed to by a user without write access

@jhump
jhump merged commit 48a551d into bufbuild:main Apr 17, 2025
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