Skip to content

Commit

Permalink
Return error on stream error for retry (#565)
Browse files Browse the repository at this point in the history
`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:
golang/go#51323

---------

Co-authored-by: Louis Garman <[email protected]>
  • Loading branch information
tomwardill-payoneer and leg100 authored Aug 13, 2023
1 parent df1645d commit 4c2c130
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
9 changes: 7 additions & 2 deletions internal/agent/spooler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,25 @@ 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)
case string:
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) {
Expand Down

0 comments on commit 4c2c130

Please sign in to comment.