Skip to content

Commit 7fe6d8c

Browse files
fix: resolve race condition
1 parent bf32b89 commit 7fe6d8c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

agent/agentscripts/agentscripts.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
338338
return
339339
}
340340

341+
// We want to check this outside of the goroutine to avoid a race condition
342+
timedOut := errors.Is(err, ErrTimeout)
343+
341344
err = r.trackCommandGoroutine(func() {
342345
var stage proto.Timing_Stage
343346
switch option {
@@ -353,14 +356,14 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript,
353356
reportCtx, cancel := context.WithTimeout(context.Background(), reportTimeout)
354357
defer cancel()
355358

356-
_, err = r.scriptCompleted(reportCtx, &proto.WorkspaceAgentScriptCompletedRequest{
359+
_, err := r.scriptCompleted(reportCtx, &proto.WorkspaceAgentScriptCompletedRequest{
357360
Timing: &proto.Timing{
358361
ScriptId: script.ID[:],
359362
Start: timestamppb.New(start),
360363
End: timestamppb.New(end),
361364
ExitCode: int32(exitCode),
362365
Stage: stage,
363-
TimedOut: errors.Is(err, ErrTimeout),
366+
TimedOut: timedOut,
364367
},
365368
})
366369
if err != nil {

0 commit comments

Comments
 (0)