Skip to content

Commit

Permalink
Add wait on processingDone to cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco de Borja Aranda Castillejo <[email protected]>
  • Loading branch information
Francisco de Borja Aranda Castillejo committed May 3, 2024
1 parent c7bbd40 commit 7803410
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion pkg/timelock/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (tw *Worker) runScheduler(ctx context.Context) <-chan struct{} {

go func() {
defer close(done)

for {
select {
case <-tw.ticker.C:
Expand Down
12 changes: 9 additions & 3 deletions pkg/timelock/timelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,22 @@ func (tw *Worker) Listen(ctx context.Context) error {
// Main goroutine; processes old and new logs and handles cancellation.
processingDone := tw.processLogs(ctxwc, historyCh, logCh)

// Block until the context is done and then cleanup.
<-ctxwc.Done()
// Block until the context is done or until processing is completed.
// This cover the two cases where timelock-worker can exit:
// - A signal to stop timelock-worker was received.
// - The subscription errored out and wasn't recovered.
select {
case <-ctxwc.Done():
case <-processingDone:
}

tw.logger.Info().Msg("shutting down timelock-worker")
tw.logger.Info().Msg("dumping operation store")
tw.dumpOperationStore(time.Now)

// Wait for all goroutines to finish.
<-historyDone
<-newDone
<-processingDone
<-schedulingDone

return nil
Expand Down

0 comments on commit 7803410

Please sign in to comment.