Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4066785

Browse files
authored
fix: agentcontainers: fix flake when ctx cancelled while running docker inspect (#18526)
Shouldfixcoder/internal#738
1 parentb091b99 commit4066785

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

‎agent/agentcontainers/api.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ func (api *API) updaterLoop() {
378378
// and anyone looking to interact with the API.
379379
api.logger.Debug(api.ctx,"performing initial containers update")
380380
iferr:=api.updateContainers(api.ctx);err!=nil {
381-
api.logger.Error(api.ctx,"initial containers update failed",slog.Error(err))
381+
iferrors.Is(err,context.Canceled) {
382+
api.logger.Warn(api.ctx,"initial containers update canceled",slog.Error(err))
383+
}else {
384+
api.logger.Error(api.ctx,"initial containers update failed",slog.Error(err))
385+
}
382386
}else {
383387
api.logger.Debug(api.ctx,"initial containers update complete")
384388
}
@@ -399,7 +403,11 @@ func (api *API) updaterLoop() {
399403
caseapi.updateTrigger<-done:
400404
err:=<-done
401405
iferr!=nil {
402-
api.logger.Error(api.ctx,"updater loop ticker failed",slog.Error(err))
406+
iferrors.Is(err,context.Canceled) {
407+
api.logger.Warn(api.ctx,"updater loop ticker canceled",slog.Error(err))
408+
}else {
409+
api.logger.Error(api.ctx,"updater loop ticker failed",slog.Error(err))
410+
}
403411
}
404412
default:
405413
api.logger.Debug(api.ctx,"updater loop ticker skipped, update in progress")

‎agent/agentcontainers/containers_dockercli.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ func (dcli *dockerCLI) List(ctx context.Context) (codersdk.WorkspaceAgentListCon
311311
// container IDs and returns the parsed output.
312312
// The stderr output is also returned for logging purposes.
313313
funcrunDockerInspect(ctx context.Context,execer agentexec.Execer,ids...string) (stdout,stderr []byte,errerror) {
314+
ifctx.Err()!=nil {
315+
// If the context is done, we don't want to run the command.
316+
return []byte{}, []byte{},ctx.Err()
317+
}
314318
varstdoutBuf,stderrBuf bytes.Buffer
315319
cmd:=execer.CommandContext(ctx,"docker",append([]string{"inspect"},ids...)...)
316320
cmd.Stdout=&stdoutBuf
@@ -319,6 +323,12 @@ func runDockerInspect(ctx context.Context, execer agentexec.Execer, ids ...strin
319323
stdout=bytes.TrimSpace(stdoutBuf.Bytes())
320324
stderr=bytes.TrimSpace(stderrBuf.Bytes())
321325
iferr!=nil {
326+
ifctx.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+
returnstdout,stderr,ctx.Err()
331+
}
322332
ifbytes.Contains(stderr, []byte("No such object:")) {
323333
// This can happen if a container is deleted between the time we check for its existence and the time we inspect it.
324334
returnstdout,stderr,nil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp