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

More log streamer cleanups #2498

Merged
merged 2 commits into from
Nov 24, 2023
Merged

More log streamer cleanups #2498

merged 2 commits into from
Nov 24, 2023

Conversation

DrJosh9000
Copy link
Contributor

@DrJosh9000 DrJosh9000 commented Nov 15, 2023

What

  • Use the WaitGroup to count workers instead of pending log uploads, averting any potential races on the WaitGroup
  • Signal to workers that work is complete by closing the channel, instead of sending nil several times
  • Handle context cancellation in worker with a select
  • Add context arg to Process, and a select to handle it there, too
  • Track whether the streamer has been stopped, and use that to return an error from Process after Stop
  • Reinstate error handling inside streamJobLogsAfterProcessStart and output buffer closing (with explanatory comment)
  • Neaten up core of Process loop
  • Doc comments
  • A test!

Why

Handling context cancellation in a select with the channel operations is, strictly speaking, a bug fix (context should be available as a lever to cancel blocked operations), but practically isn't used here.

Returning an error from Process after Stop is a behaviour change that is similarly theoretical (if the job is always stopped, and Process is never called again before Stop). But it is an improvement: before, if Stop is called then there is the possibility that, if all the workers are stopped and Process is called again, the chunk is left in the channel until the program exits, or potentially the queue fills up and the goroutine managing the streamer blocks forever. Now, Process at least returns an error.

This also means that we can be more explicit about closing the queue and then actually wait for for the workers to finish, rather than waiting for current work to finish before yeeting nil several times into the (buffered) queue channel and not actually waiting them to shut down (this always seemed weird and backwards to me).

Notes

Note that this does not enable log limit enforcement (yet).

- Use the WaitGroup to count workers instead of pending log uploads, averting any potential races on the WaitGroup
- Signal to workers that work is complete by closing the channel, instead of sending nil several times
- Handle context cancellation in worker with a select
- Add context arg to Process, and a select to handle it there, too
- Track whether the streamer has been stopped, and use that to return an error from Process.
- Reinstate error handling inside streamJobLogsAfterProcessStart
- Neaten up core of Process loop
- Doc comments
Copy link
Contributor

@triarius triarius left a comment

Choose a reason for hiding this comment

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

Very Nice!

@DrJosh9000 DrJosh9000 merged commit 268453c into main Nov 24, 2023
@DrJosh9000 DrJosh9000 deleted the log-limit branch November 24, 2023 11:32
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.

2 participants