[27.x backport] oauth/api: drain timer channel on each iteration #5399
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5375
- What I did
Previously, if while polling for oauth device-code login results a user suspended the process (such as with CTRL-Z) and then restored it with
fg
, an error might occur in the form of:This is due to our use of a
time.Ticker
here - if no receiver drains the ticker channel (and timers/tickers use a buffered channel behind the scenes), more than one tick will pile up, causing the program to "tick" twice, in fast succession, after it is resumed.- How I did it
The new implementation replaces the
time.Ticker
with atime.Timer
(time.Ticker
is just a nice wrapper) and introduces a helper functionresetTimer
to ensure that before everyselect
, the timer is stopped and it's channel is drained.- How to verify it
Reproduce as described in #5375
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)