Skip to content

Commit 4c2c130

Browse files
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: golang/go#51323 --------- Co-authored-by: Louis Garman <[email protected]>
1 parent df1645d commit 4c2c130

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: internal/agent/agent.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ func (a *agent) Start(ctx context.Context) error {
116116

117117
g.Go(func() error {
118118
if err := a.spooler.start(ctx); err != nil {
119-
return fmt.Errorf("spooler terminated: %w", err)
119+
// only report error if context has not been canceled
120+
if ctx.Err() == nil {
121+
return fmt.Errorf("spooler terminated: %w", err)
122+
}
120123
}
121124
return nil
122125
})

Diff for: internal/agent/spooler.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,25 @@ func (s *spoolerDaemon) reinitialize(ctx context.Context) error {
110110
}
111111
// then spool events as they come in
112112
for event := range sub {
113-
s.handleEvent(event)
113+
err = s.handleEvent(event)
114+
if err != nil {
115+
return err
116+
}
114117
}
115118
return nil
116119
}
117120

118-
func (s *spoolerDaemon) handleEvent(ev pubsub.Event) {
121+
func (s *spoolerDaemon) handleEvent(ev pubsub.Event) error {
119122
switch payload := ev.Payload.(type) {
120123
case *run.Run:
121124
s.handleRun(ev.Type, payload)
122125
case string:
123126
s.Info("stream update", "info", string(payload))
124127
case error:
125128
s.Error(payload, "stream update")
129+
return payload
126130
}
131+
return nil
127132
}
128133

129134
func (s *spoolerDaemon) handleRun(event pubsub.EventType, run *run.Run) {

0 commit comments

Comments
 (0)