Skip to content

Commit d1f4963

Browse files
committed
Fix timeout draining
1 parent 73a7a78 commit d1f4963

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

agent/agentscripts/agentscripts.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (r *Runner) Execute(ctx context.Context, filter func(script codersdk.Worksp
116116
eg.Go(func() error {
117117
err := r.run(ctx, script)
118118
if err != nil {
119-
return xerrors.Errorf("run agent script %q: %w", script.LogPath, err)
119+
return xerrors.Errorf("run agent script %q: %w", script.LogSourceID, err)
120120
}
121121
return nil
122122
})
@@ -217,8 +217,13 @@ func (r *Runner) run(ctx context.Context, script codersdk.WorkspaceAgentScript)
217217
return xerrors.Errorf("%s script: track command goroutine: %w", logPath, err)
218218
}
219219
select {
220-
case <-ctx.Done():
221-
err = ctx.Err()
220+
case <-cmdCtx.Done():
221+
// Wait for the command to drain!
222+
select {
223+
case <-cmdDone:
224+
case <-time.After(10 * time.Second):
225+
}
226+
err = cmdCtx.Err()
222227
case err = <-cmdDone:
223228
}
224229
if errors.Is(err, context.DeadlineExceeded) {

0 commit comments

Comments
 (0)