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

Simplify timer cleanup #42

Merged
merged 1 commit into from
Jan 13, 2024
Merged

Simplify timer cleanup #42

merged 1 commit into from
Jan 13, 2024

Conversation

eapache
Copy link
Owner

@eapache eapache commented Jan 13, 2024

The timer channels are created with a buffer. Because we aren't reusing them, we don't need to worry about draining that channel; the internal goroutine will still be able to write to the buffer and exit gracefully, at which point the GC will clean it all up.

We do still need to call Stop() to tell the timer to clean up immediately, as otherwise it will run for its full duration which (in a tight loop) can cause timer goroutines to pile up.

@rjeczalik I still think this is just a minor simplification that won't have any noticeable performance impact, but you were right in #41 that draining the channel is technically unnecessary.

cc @dnozdrin as you reported the initial memory issue with the timer goroutines piling up; as far as I can tell this should still be safe in that regard

The timer channels are created with a buffer. Because we aren't reusing them,
we don't need to worry about draining that channel; the internal
goroutine will still be able to write to the buffer and exit gracefully,
at which point the GC will clean it all up.

We *do* still need to call `Stop()` to tell the timer to clean up
immediately, as otherwise it will run for its full duration which (in a
tight loop) can cause timer goroutines to pile up.
@eapache eapache merged commit f26ac90 into main Jan 13, 2024
4 checks passed
@eapache eapache deleted the simplify-timers branch January 13, 2024 16:27
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.

None yet

1 participant