-
Notifications
You must be signed in to change notification settings - Fork 1
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
timelock: handle log processing shutdown and Listen shutdown #55
Conversation
@@ -154,16 +155,18 @@ func (tw *Worker) Listen() error { | |||
select { | |||
case <-ctxwc.Done(): | |||
case <-processingDone: | |||
cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call cancel here to stop the scheduling routine
<-historyDone | ||
<-newDone | ||
<-schedulingDone | ||
shutdownCtx, cancel := context.WithTimeout(context.Background(), time.Second*5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a new context as the previous one is either done or was canceled
done := make(chan struct{}) | ||
var ( | ||
done, newDone, oldDone = make(chan struct{}), make(chan struct{}), make(chan struct{}) | ||
ctxwc, cancel = context.WithCancel(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a child context we can cancel when both log channels are closed
if err := tw.handleLog(ctx, log); err != nil { | ||
case log, open := <-newLog: | ||
if !open { | ||
close(newDone) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if newLog is closed, signal new logs are done and set the channel to nil so this branch never is selected again
This PR shuts down the log processing goroutine if both log channels are closed. If both log channels close, then the context is canceled which forces a shutdown.
This PR also cancels the scheduling goroutine in the event that the processing goroutine shuts down. Once the Listen method starts to shutdown the worker, it now waits for all goroutines to finish with only a five second grace period.