From 6d03aa0684e4063965d3df2bcbec082ffec69685 Mon Sep 17 00:00:00 2001 From: JeanCarlos_MartinsDa Date: Tue, 18 Aug 2026 18:16:35 -0300 Subject: [PATCH 1/2] add worker reconnection logging to improve connection observability --- backend/worker.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/worker.go b/backend/worker.go index 640e7bc3..8dcef02f 100644 --- a/backend/worker.go +++ b/backend/worker.go @@ -47,6 +47,8 @@ type worker struct { processor TaskProcessor waiting bool stop atomic.Bool + // consecutiveErrors tracks connection failures for reconnection logging + consecutiveErrors atomic.Int32 } type NewTaskWorkerOptions func(*WorkerOptions) @@ -113,6 +115,9 @@ func (w *worker) Start(ctx context.Context) { switch { case ok: // found a work item - reset the backoff and check for the next item + if w.waiting { + w.logger.Infof("%v: reconnected and ready to process work items", w.Name()) + } b.Reset() case err != nil && errors.Is(err, ctx.Err()): // there's an error and it's due to the context being canceled @@ -174,6 +179,11 @@ func (w *worker) ProcessNext(ctx context.Context) (bool, error) { wi, err := w.processor.FetchWorkItem(ctx) switch { case errors.Is(err, ErrNoWorkItems) || wi == nil: + // Check if we recovered from connection errors + if w.consecutiveErrors.Load() > 0 { + w.logger.Infof("%v: reconnected and ready to process work items", w.Name()) + w.consecutiveErrors.Store(0) + } if !w.waiting { w.logger.Debugf("%v: waiting for new work items...", w.Name()) w.waiting = true @@ -182,9 +192,16 @@ func (w *worker) ProcessNext(ctx context.Context) (bool, error) { case err != nil: if !errors.Is(err, ctx.Err()) { w.logger.Errorf("%v: failed to fetch work item: %v", w.Name(), err) + // Increment error counter for connection-related errors + w.consecutiveErrors.Add(1) } return false, err default: + // Check if we recovered from connection errors when successfully fetching work item + if w.consecutiveErrors.Load() > 0 { + w.logger.Infof("%v: reconnected and ready to process work items", w.Name()) + w.consecutiveErrors.Store(0) + } // process the work-item in the background w.waiting = false processing = true From fa76989a359bb1346e700abe69593f59f723a9ac Mon Sep 17 00:00:00 2001 From: JeanCarlos_MartinsDa Date: Tue, 18 Aug 2026 18:34:22 -0300 Subject: [PATCH 2/2] improve worker reconnection logging based on code review feedback - Remove dependency on w.waiting for reconnection detection - Update comment from 'connection-related errors' to 'fetch failures' for accuracy - Keep reconnection logging in both branches (with and without work items) - Maintain error log duplication as preferred This addresses feedback about w.waiting representing work item state rather than connection state, and makes error tracking more accurate. --- backend/worker.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/worker.go b/backend/worker.go index 8dcef02f..03869e84 100644 --- a/backend/worker.go +++ b/backend/worker.go @@ -179,7 +179,7 @@ func (w *worker) ProcessNext(ctx context.Context) (bool, error) { wi, err := w.processor.FetchWorkItem(ctx) switch { case errors.Is(err, ErrNoWorkItems) || wi == nil: - // Check if we recovered from connection errors + // Check if we recovered from errors when no work items if w.consecutiveErrors.Load() > 0 { w.logger.Infof("%v: reconnected and ready to process work items", w.Name()) w.consecutiveErrors.Store(0) @@ -192,12 +192,12 @@ func (w *worker) ProcessNext(ctx context.Context) (bool, error) { case err != nil: if !errors.Is(err, ctx.Err()) { w.logger.Errorf("%v: failed to fetch work item: %v", w.Name(), err) - // Increment error counter for connection-related errors + // Increment error counter for fetch failures w.consecutiveErrors.Add(1) } return false, err default: - // Check if we recovered from connection errors when successfully fetching work item + // Check if we recovered from errors when successfully fetching work item if w.consecutiveErrors.Load() > 0 { w.logger.Infof("%v: reconnected and ready to process work items", w.Name()) w.consecutiveErrors.Store(0)