Skip to content

Commit 4a46f67

Browse files
committed
pr changes
1 parent 43b47f4 commit 4a46f67

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

cli/docker.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,19 @@ func dockerCmd() *cobra.Command {
226226
// Start sysbox-mgr and sysbox-fs in order to run
227227
// sysbox containers.
228228
case err := <-background.New(ctx, log, "sysbox-mgr", sysboxArgs...).Run():
229-
blog.Info(sysboxErrMsg)
230-
//nolint
231-
log.Critical(ctx, "sysbox-mgr exited", slog.Error(err))
232-
panic(err)
229+
if ctx.Err() == nil {
230+
blog.Info(sysboxErrMsg)
231+
//nolint
232+
log.Critical(ctx, "sysbox-mgr exited", slog.Error(err))
233+
panic(err)
234+
}
233235
case err := <-background.New(ctx, log, "sysbox-fs").Run():
234-
blog.Info(sysboxErrMsg)
235-
//nolint
236-
log.Critical(ctx, "sysbox-fs exited", slog.Error(err))
237-
panic(err)
236+
if ctx.Err() == nil {
237+
blog.Info(sysboxErrMsg)
238+
//nolint
239+
log.Critical(ctx, "sysbox-fs exited", slog.Error(err))
240+
panic(err)
241+
}
238242
}
239243
}()
240244

@@ -384,31 +388,31 @@ func dockerCmd() *cobra.Command {
384388
return
385389
}
386390

387-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*90)
388-
defer cancel()
391+
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), time.Second*90)
392+
defer shutdownCancel()
389393

390-
bootstrapPID, err := dockerutil.GetExecPID(ctx, client, bootstrapExecID)
394+
bootstrapPID, err := dockerutil.GetExecPID(shutdownCtx, client, bootstrapExecID)
391395
if err != nil {
392-
log.Error(ctx, "get exec pid", slog.Error(err))
396+
log.Error(shutdownCtx, "get exec pid", slog.Error(err))
393397
}
394398

395-
log.Debug(ctx, "killing container", slog.F("bootstrap_pid", bootstrapPID))
399+
log.Debug(shutdownCtx, "killing container", slog.F("bootstrap_pid", bootstrapPID))
396400

397401
// The PID returned is the PID _outside_ the container...
398-
out, err := exec.Command("kill", "-TERM", strconv.Itoa(bootstrapPID)).CombinedOutput() //nolint:gosec
402+
out, err := exec.CommandContext(shutdownCtx, "kill", "-TERM", strconv.Itoa(bootstrapPID)).CombinedOutput() //nolint:gosec
399403
if err != nil {
400-
log.Error(ctx, "kill bootstrap process", slog.Error(err), slog.F("output", string(out)))
404+
log.Error(shutdownCtx, "kill bootstrap process", slog.Error(err), slog.F("output", string(out)))
401405
return
402406
}
403407

404-
log.Debug(ctx, "sent kill signal waiting for process to exit")
405-
err = dockerutil.WaitForExit(ctx, client, bootstrapExecID)
408+
log.Debug(shutdownCtx, "sent kill signal waiting for process to exit")
409+
err = dockerutil.WaitForExit(shutdownCtx, client, bootstrapExecID)
406410
if err != nil {
407-
log.Error(ctx, "wait for exit", slog.Error(err))
411+
log.Error(shutdownCtx, "wait for exit", slog.Error(err))
408412
return
409413
}
410414

411-
log.Debug(ctx, "bootstrap process successfully exited")
415+
log.Debug(shutdownCtx, "bootstrap process successfully exited")
412416
}()
413417

414418
return nil

dockerutil/dockerfake/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (m MockClient) ContainerExecCreate(ctx context.Context, name string, config
164164
func (m MockClient) ContainerExecInspect(ctx context.Context, id string) (dockertypes.ContainerExecInspect, error) {
165165
if m.ContainerExecInspectFn == nil {
166166
return dockertypes.ContainerExecInspect{
167-
Pid: 1,
167+
Pid: 123,
168168
}, nil
169169
}
170170

0 commit comments

Comments
 (0)