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

timelock: handle log processing shutdown and Listen shutdown #55

Merged
merged 3 commits into from
May 3, 2024

Conversation

MStreet3
Copy link
Collaborator

@MStreet3 MStreet3 commented May 3, 2024

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.

@MStreet3 MStreet3 requested a review from fbac May 3, 2024 18:36
@@ -154,16 +155,18 @@ func (tw *Worker) Listen() error {
select {
case <-ctxwc.Done():
case <-processingDone:
cancel()
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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

@fbac fbac merged commit 31a570a into ethclient-refactor May 3, 2024
3 checks passed
@MStreet3 MStreet3 deleted the street/close-processing branch May 3, 2024 19:21
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