From 9ddf72fa37ec526be241e9b1086ce20daffc8bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 16 Jun 2022 12:19:03 +0200 Subject: [PATCH] Worker: sign off as last step of shutdown Within the shutdown procedure, signing off is now the last thing the worker does. This makes things more consistent from the Manager's point of view (like receiving last-second log entries while the Worker is still online). --- cmd/flamenco-worker/main.go | 8 +++++--- internal/worker/worker.go | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/flamenco-worker/main.go b/cmd/flamenco-worker/main.go index efc6e428..67462402 100644 --- a/cmd/flamenco-worker/main.go +++ b/cmd/flamenco-worker/main.go @@ -144,14 +144,16 @@ func shutdown() { done := make(chan struct{}) go func() { if w != nil { - shutdownCtx, cancelFunc := context.WithTimeout(context.Background(), 3*time.Second) - defer cancelFunc() - w.SignOff(shutdownCtx) w.Close() listener.Wait() if err := buffer.Close(); err != nil { log.Error().Err(err).Msg("closing upstream task buffer") } + + // Sign off as the last step. Any flushes should happen while we're still signed on. + signoffCtx, cancelFunc := context.WithTimeout(context.Background(), 3*time.Second) + defer cancelFunc() + w.SignOff(signoffCtx) } close(done) }() diff --git a/internal/worker/worker.go b/internal/worker/worker.go index a2f8151d..9d45e8db 100644 --- a/internal/worker/worker.go +++ b/internal/worker/worker.go @@ -63,5 +63,4 @@ func (w *Worker) Close() { log.Debug().Msg("worker gracefully shutting down") close(w.doneChan) w.doneWg.Wait() - log.Debug().Msg("worker shut down") }