@@ -311,6 +311,10 @@ func (dcli *dockerCLI) List(ctx context.Context) (codersdk.WorkspaceAgentListCon
311
311
// container IDs and returns the parsed output.
312
312
// The stderr output is also returned for logging purposes.
313
313
func runDockerInspect (ctx context.Context , execer agentexec.Execer , ids ... string ) (stdout , stderr []byte , err error ) {
314
+ if ctx .Err () != nil {
315
+ // If the context is done, we don't want to run the command.
316
+ return []byte {}, []byte {}, ctx .Err ()
317
+ }
314
318
var stdoutBuf , stderrBuf bytes.Buffer
315
319
cmd := execer .CommandContext (ctx , "docker" , append ([]string {"inspect" }, ids ... )... )
316
320
cmd .Stdout = & stdoutBuf
@@ -319,6 +323,12 @@ func runDockerInspect(ctx context.Context, execer agentexec.Execer, ids ...strin
319
323
stdout = bytes .TrimSpace (stdoutBuf .Bytes ())
320
324
stderr = bytes .TrimSpace (stderrBuf .Bytes ())
321
325
if err != nil {
326
+ if ctx .Err () != nil {
327
+ // If the context was canceled while running the command,
328
+ // return the context error instead of the command error,
329
+ // which is likely to be "signal: killed".
330
+ return stdout , stderr , ctx .Err ()
331
+ }
322
332
if bytes .Contains (stderr , []byte ("No such object:" )) {
323
333
// This can happen if a container is deleted between the time we check for its existence and the time we inspect it.
324
334
return stdout , stderr , nil
0 commit comments