Skip to content

Commit 55b6640

Browse files
committed
libcontainer/windows: Fix process not being killed after stdio attach failure
Error check in defer block used wrong error variable which is always nil if the flow reaches the defer. This caused the `newProcess.Kill` to be never called if the subsequent attemp to attach to the stdio failed. Although this only happens in Exec (as Start does overwrite the error), this also adjusts the Start to also use the returned error to avoid this kind of mistake in future changes. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 39b2bf5 commit 55b6640

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

libcontainerd/local/local_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func (c *client) extractResourcesFromSpec(spec *specs.Spec, configuration *hcssh
389389
}
390390
}
391391

392-
func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (libcontainerdtypes.Task, error) {
392+
func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (_ libcontainerdtypes.Task, retErr error) {
393393
ctr.mu.Lock()
394394
defer ctr.mu.Unlock()
395395

@@ -446,7 +446,7 @@ func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachS
446446
}
447447

448448
defer func() {
449-
if err != nil {
449+
if retErr != nil {
450450
if err := newProcess.Kill(); err != nil {
451451
logger.WithError(err).Error("failed to kill process")
452452
}
@@ -557,7 +557,7 @@ func newIOFromProcess(newProcess hcsshim.Process, terminal bool) (*cio.DirectIO,
557557
// The processID argument is entirely informational. As there is no mechanism
558558
// (exposed through the libcontainerd interfaces) to enumerate or reference an
559559
// exec'd process by ID, uniqueness is not currently enforced.
560-
func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (libcontainerdtypes.Process, error) {
560+
func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (_ libcontainerdtypes.Process, retErr error) {
561561
hcsContainer, err := t.getHCSContainer()
562562
if err != nil {
563563
return nil, err
@@ -610,7 +610,7 @@ func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process,
610610
}
611611
pid := newProcess.Pid()
612612
defer func() {
613-
if err != nil {
613+
if retErr != nil {
614614
if err := newProcess.Kill(); err != nil {
615615
logger.WithError(err).Error("failed to kill process")
616616
}

0 commit comments

Comments
 (0)