Przeglądaj źródła

libcontainerd/windows: Don't reap on failure

Synchronize the code to do the same thing as Exec.
reap doesn't need to be called before the start event was sent.
There's already a defer block which cleans up the process in case where
an error occurs.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 1 rok temu
rodzic
commit
0937aef261
1 zmienionych plików z 16 dodań i 14 usunięć
  1. 16 14
      libcontainerd/local/local_windows.go

+ 16 - 14
libcontainerd/local/local_windows.go

@@ -460,19 +460,9 @@ func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachS
 			}()
 			}()
 		}
 		}
 	}()
 	}()
-	t := &task{process: process{
-		id:         ctr.id,
-		ctr:        ctr,
-		hcsProcess: newProcess,
-		waitCh:     make(chan struct{}),
-	}}
-	pid := t.Pid()
-	logger.WithField("pid", pid).Debug("init process started")
 
 
-	// Spin up a goroutine to notify the backend and clean up resources when
-	// the task exits. Defer until after the start event is sent so that the
-	// exit event is not sent out-of-order.
-	defer func() { go t.reap() }()
+	pid := newProcess.Pid()
+	logger.WithField("pid", pid).Debug("init process started")
 
 
 	dio, err := newIOFromProcess(newProcess, ctr.ociSpec.Process.Terminal)
 	dio, err := newIOFromProcess(newProcess, ctr.ociSpec.Process.Terminal)
 	if err != nil {
 	if err != nil {
@@ -485,16 +475,28 @@ func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachS
 		return nil, err
 		return nil, err
 	}
 	}
 
 
+	t := &task{process{
+		id:         ctr.id,
+		ctr:        ctr,
+		hcsProcess: newProcess,
+		waitCh:     make(chan struct{}),
+	}}
+
 	// All fallible operations have succeeded so it is now safe to set the
 	// All fallible operations have succeeded so it is now safe to set the
 	// container's current task.
 	// container's current task.
 	ctr.task = t
 	ctr.task = t
 
 
+	// Spin up a goroutine to notify the backend and clean up resources when
+	// the task exits. Defer until after the start event is sent so that the
+	// exit event is not sent out-of-order.
+	defer func() { go t.reap() }()
+
 	// Generate the associated event
 	// Generate the associated event
 	ctr.client.eventQ.Append(ctr.id, func() {
 	ctr.client.eventQ.Append(ctr.id, func() {
 		ei := libcontainerdtypes.EventInfo{
 		ei := libcontainerdtypes.EventInfo{
 			ContainerID: ctr.id,
 			ContainerID: ctr.id,
 			ProcessID:   t.id,
 			ProcessID:   t.id,
-			Pid:         pid,
+			Pid:         uint32(pid),
 		}
 		}
 		ctr.client.logger.WithFields(log.Fields{
 		ctr.client.logger.WithFields(log.Fields{
 			"container":  ctr.id,
 			"container":  ctr.id,
@@ -606,7 +608,6 @@ func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process,
 		logger.WithError(err).Errorf("exec's CreateProcess() failed")
 		logger.WithError(err).Errorf("exec's CreateProcess() failed")
 		return nil, err
 		return nil, err
 	}
 	}
-	pid := newProcess.Pid()
 	defer func() {
 	defer func() {
 		if retErr != nil {
 		if retErr != nil {
 			if err := newProcess.Kill(); err != nil {
 			if err := newProcess.Kill(); err != nil {
@@ -646,6 +647,7 @@ func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process,
 	// the exit event is not sent out-of-order.
 	// the exit event is not sent out-of-order.
 	defer func() { go p.reap() }()
 	defer func() { go p.reap() }()
 
 
+	pid := newProcess.Pid()
 	t.ctr.client.eventQ.Append(t.ctr.id, func() {
 	t.ctr.client.eventQ.Append(t.ctr.id, func() {
 		ei := libcontainerdtypes.EventInfo{
 		ei := libcontainerdtypes.EventInfo{
 			ContainerID: t.ctr.id,
 			ContainerID: t.ctr.id,