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) {