@@ -220,22 +220,19 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
220220 }
221221 defer func () {
222222 // Stop the container
223-
224- if terminateMode {
225- logrus .Debugf ("Terminating container %s" , c .ID )
226- if err := hcsshim .TerminateComputeSystem (c .ID ); err != nil {
227- // IMPORTANT: Don't fail if fails to change state. It could already
228- // have been stopped through kill().
229- // Otherwise, the docker daemon will hang in job wait()
230- logrus .Warnf ("Ignoring error from TerminateComputeSystem %s" , err )
223+ if forceKill {
224+ logrus .Debugf ("Forcibly terminating container %s" , c .ID )
225+ if errno , err := hcsshim .TerminateComputeSystem (c .ID , hcsshim .TimeoutInfinite , "exec-run-defer" ); err != nil {
226+ logrus .Warnf ("Ignoring error from TerminateComputeSystem 0x%X %s" , errno , err )
231227 }
232228 } else {
233229 logrus .Debugf ("Shutting down container %s" , c .ID )
234- if err := hcsshim .ShutdownComputeSystem (c .ID ); err != nil {
235- // IMPORTANT: Don't fail if fails to change state. It could already
236- // have been stopped through kill().
237- // Otherwise, the docker daemon will hang in job wait()
238- logrus .Warnf ("Ignoring error from ShutdownComputeSystem %s" , err )
230+ if errno , err := hcsshim .ShutdownComputeSystem (c .ID , hcsshim .TimeoutInfinite , "exec-run-defer" ); err != nil {
231+ if errno != hcsshim .Win32SystemShutdownIsInProgress &&
232+ errno != hcsshim .Win32SpecifiedPathInvalid &&
233+ errno != hcsshim .Win32SystemCannotFindThePathSpecified {
234+ logrus .Warnf ("Ignoring error from ShutdownComputeSystem 0x%X %s" , errno , err )
235+ }
239236 }
240237 }
241238 }()
@@ -303,11 +300,20 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
303300 hooks .Start (& c .ProcessConfig , int (pid ), chOOM )
304301 }
305302
306- var exitCode int32
307- exitCode , err = hcsshim .WaitForProcessInComputeSystem (c .ID , pid )
303+ var (
304+ exitCode int32
305+ errno uint32
306+ )
307+ exitCode , errno , err = hcsshim .WaitForProcessInComputeSystem (c .ID , pid , hcsshim .TimeoutInfinite )
308308 if err != nil {
309- logrus .Errorf ("Failed to WaitForProcessInComputeSystem %s" , err )
310- return execdriver.ExitStatus {ExitCode : - 1 }, err
309+ if errno != hcsshim .Win32PipeHasBeenEnded {
310+ logrus .Warnf ("WaitForProcessInComputeSystem failed (container may have been killed): %s" , err )
311+ }
312+ // Do NOT return err here as the container would have
313+ // started, otherwise docker will deadlock. It's perfectly legitimate
314+ // for WaitForProcessInComputeSystem to fail in situations such
315+ // as the container being killed on another thread.
316+ return execdriver.ExitStatus {ExitCode : hcsshim .WaitErrExecFailed }, nil
311317 }
312318
313319 logrus .Debugf ("Exiting Run() exitCode %d id=%s" , exitCode , c .ID )
0 commit comments