From 4c2c1307de160796fb076b71853ec7156be5b0e9 Mon Sep 17 00:00:00 2001 From: Tom Wardill <89394722+tomwardill-payoneer@users.noreply.github.com> Date: Sun, 13 Aug 2023 20:28:49 +0100 Subject: [PATCH] Return error on stream error for retry (#565) `handleEvent` was handling the an `error` type by printing something, but then not continuing to raise the error. This means that in a stream error, particuarly of type INTERNAL_ERROR, the backoff/retry mechanism never took place as the return was `nil` and the agent just stopped. The problem is particularly relevant with Google Load Balancers and their handling of http2/websocket long lived connections: https://github.com/golang/go/issues/51323 --------- Co-authored-by: Louis Garman --- internal/agent/agent.go | 5 ++++- internal/agent/spooler.go | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/agent/agent.go b/internal/agent/agent.go index cd30a44ec..0c62fe12e 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -116,7 +116,10 @@ func (a *agent) Start(ctx context.Context) error { g.Go(func() error { if err := a.spooler.start(ctx); err != nil { - return fmt.Errorf("spooler terminated: %w", err) + // only report error if context has not been canceled + if ctx.Err() == nil { + return fmt.Errorf("spooler terminated: %w", err) + } } return nil }) diff --git a/internal/agent/spooler.go b/internal/agent/spooler.go index 57ed7104f..2d49631e5 100644 --- a/internal/agent/spooler.go +++ b/internal/agent/spooler.go @@ -110,12 +110,15 @@ func (s *spoolerDaemon) reinitialize(ctx context.Context) error { } // then spool events as they come in for event := range sub { - s.handleEvent(event) + err = s.handleEvent(event) + if err != nil { + return err + } } return nil } -func (s *spoolerDaemon) handleEvent(ev pubsub.Event) { +func (s *spoolerDaemon) handleEvent(ev pubsub.Event) error { switch payload := ev.Payload.(type) { case *run.Run: s.handleRun(ev.Type, payload) @@ -123,7 +126,9 @@ func (s *spoolerDaemon) handleEvent(ev pubsub.Event) { s.Info("stream update", "info", string(payload)) case error: s.Error(payload, "stream update") + return payload } + return nil } func (s *spoolerDaemon) handleRun(event pubsub.EventType, run *run.Run) {