Skip to content

Commit 30e157e

Browse files
authored
fix: handle gracefully watcher error (#6316)
1 parent fa4a354 commit 30e157e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pkg/runner/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (s *service) recover(ctx context.Context) (err error) {
8888

8989
for _, exec := range executions {
9090
go func(environmentId string, executionId string) {
91-
err := s.runner.Monitor(ctx, s.proContext.OrgID, environmentId, executionId)
91+
err := s.runner.Monitor(context.Background(), s.proContext.OrgID, environmentId, executionId)
9292
if err == nil {
9393
return
9494
}

pkg/testworkflows/executionworker/controller/watchinstrumentedpod.go

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ func WatchInstrumentedPod(parentCtx context.Context, clientSet kubernetes.Interf
3939
}
4040

4141
notifier.Align(watcher.State())
42+
43+
if ctx.Err() != nil {
44+
log.DefaultLogger.Warnw("canceled watching execution", "executionId", watcher.State().ResourceId(), "err", ctx.Err(), "debug", watcher.State().Debug())
45+
close(notifier.ch)
46+
return
47+
}
48+
49+
if !watcher.State().Completed() {
50+
log.DefaultLogger.Warnw("execution was not detected as complete", "executionId", watcher.State().ResourceId(), "err", ctx.Err(), "debug", watcher.State().Debug())
51+
close(notifier.ch)
52+
return
53+
}
54+
4255
notifier.End()
4356
ctxCancel()
4457
close(notifier.ch)
@@ -85,12 +98,14 @@ func WatchInstrumentedPod(parentCtx context.Context, clientSet kubernetes.Interf
8598
// Handle the case when it has been complete without pod start
8699
if !watcher.State().PodStarted() && (watcher.State().Completed() || opts.DisableFollow) {
87100
notifier.Align(watcher.State())
101+
log.DefaultLogger.Warnw("execution complete without pod start", "executionId", watcher.State().ResourceId(), "debug", watcher.State().Debug())
88102
return
89103
}
90104

91105
// Load the pod information
92106
if watcher.State().EstimatedPodStartTimestamp().IsZero() {
93107
notifier.Error(fmt.Errorf("cannot estimate Pod start"))
108+
log.DefaultLogger.Warnw("cannot estimate execution pod start", "executionId", watcher.State().ResourceId(), "debug", watcher.State().Debug())
94109
return
95110
}
96111

@@ -100,6 +115,7 @@ func WatchInstrumentedPod(parentCtx context.Context, clientSet kubernetes.Interf
100115
actions, err := watcher.State().ActionGroups()
101116
if err != nil {
102117
notifier.Error(fmt.Errorf("cannot read execution instructions: %v", err))
118+
log.DefaultLogger.Warnw("cannot read execution instructions", "executionId", watcher.State().ResourceId(), "debug", watcher.State().Debug())
103119
return
104120
}
105121
refs, endRefs := ExtractRefsFromActionGroup(actions)

0 commit comments

Comments
 (0)