Skip to content

Commit eb68b90

Browse files
stevenhcrosbymichael
authored andcommitted
Prevent invalid errors from terminate
Both Process.Kill() and Process.Wait() can return errors that don't impact the correct behaviour of terminate. Instead of letting these get returned and logged, which causes confusion, silently ignore them. Currently the test needs to be a string test as the errors are private to the runtime packages, so its our only option. This can be seen if init fails during the setns. Signed-off-by: Steven Hartland <[email protected]>
1 parent 4693fae commit eb68b90

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

libcontainer/container_linux.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (c *linuxContainer) start(process *Process, isInit bool) error {
289289
}
290290
if err := parent.start(); err != nil {
291291
// terminate the process to ensure that it properly is reaped.
292-
if err := parent.terminate(); err != nil {
292+
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
293293
logrus.Warn(err)
294294
}
295295
return newSystemErrorWithCause(err, "starting container process")
@@ -315,7 +315,7 @@ func (c *linuxContainer) start(process *Process, isInit bool) error {
315315
}
316316
for i, hook := range c.config.Hooks.Poststart {
317317
if err := hook.Run(s); err != nil {
318-
if err := parent.terminate(); err != nil {
318+
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
319319
logrus.Warn(err)
320320
}
321321
return newSystemErrorWithCausef(err, "running poststart hook %d", i)
@@ -1774,3 +1774,20 @@ func (c *linuxContainer) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Na
17741774

17751775
return bytes.NewReader(r.Serialize()), nil
17761776
}
1777+
1778+
// ignoreTerminateErrors returns nil if the given err matches an error known
1779+
// to indicate that the terminate occurred successfully or err was nil, otherwise
1780+
// err is returned unaltered.
1781+
func ignoreTerminateErrors(err error) error {
1782+
if err == nil {
1783+
return nil
1784+
}
1785+
1786+
// TODO(steve): Update these to none string checks if the runtime exports them.
1787+
switch err.Error() {
1788+
case "os: process already finished", "exec: Wait was already called":
1789+
return nil
1790+
default:
1791+
return err
1792+
}
1793+
}

0 commit comments

Comments
 (0)