@@ -460,19 +460,9 @@ func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachS
460460 }()
461461 }
462462 }()
463- t := & task {process : process {
464- id : ctr .id ,
465- ctr : ctr ,
466- hcsProcess : newProcess ,
467- waitCh : make (chan struct {}),
468- }}
469- pid := t .Pid ()
470- logger .WithField ("pid" , pid ).Debug ("init process started" )
471463
472- // Spin up a goroutine to notify the backend and clean up resources when
473- // the task exits. Defer until after the start event is sent so that the
474- // exit event is not sent out-of-order.
475- defer func () { go t .reap () }()
464+ pid := newProcess .Pid ()
465+ logger .WithField ("pid" , pid ).Debug ("init process started" )
476466
477467 dio , err := newIOFromProcess (newProcess , ctr .ociSpec .Process .Terminal )
478468 if err != nil {
@@ -485,16 +475,28 @@ func (ctr *container) Start(_ context.Context, _ string, withStdin bool, attachS
485475 return nil , err
486476 }
487477
478+ t := & task {process {
479+ id : ctr .id ,
480+ ctr : ctr ,
481+ hcsProcess : newProcess ,
482+ waitCh : make (chan struct {}),
483+ }}
484+
488485 // All fallible operations have succeeded so it is now safe to set the
489486 // container's current task.
490487 ctr .task = t
491488
489+ // Spin up a goroutine to notify the backend and clean up resources when
490+ // the task exits. Defer until after the start event is sent so that the
491+ // exit event is not sent out-of-order.
492+ defer func () { go t .reap () }()
493+
492494 // Generate the associated event
493495 ctr .client .eventQ .Append (ctr .id , func () {
494496 ei := libcontainerdtypes.EventInfo {
495497 ContainerID : ctr .id ,
496498 ProcessID : t .id ,
497- Pid : pid ,
499+ Pid : uint32 ( pid ) ,
498500 }
499501 ctr .client .logger .WithFields (log.Fields {
500502 "container" : ctr .id ,
@@ -606,7 +608,6 @@ func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process,
606608 logger .WithError (err ).Errorf ("exec's CreateProcess() failed" )
607609 return nil , err
608610 }
609- pid := newProcess .Pid ()
610611 defer func () {
611612 if retErr != nil {
612613 if err := newProcess .Kill (); err != nil {
@@ -646,6 +647,7 @@ func (t *task) Exec(ctx context.Context, processID string, spec *specs.Process,
646647 // the exit event is not sent out-of-order.
647648 defer func () { go p .reap () }()
648649
650+ pid := newProcess .Pid ()
649651 t .ctr .client .eventQ .Append (t .ctr .id , func () {
650652 ei := libcontainerdtypes.EventInfo {
651653 ContainerID : t .ctr .id ,
0 commit comments