Skip to content

Commit 74a1729

Browse files
authored
Merge pull request #1607 from crosbymichael/term-err
libcontainer: handler errors from terminate
2 parents e8b9b92 + bfe3058 commit 74a1729

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

libcontainer/container_linux.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (c *linuxContainer) start(process *Process, isInit bool) error {
290290
}
291291
if err := parent.start(); err != nil {
292292
// terminate the process to ensure that it properly is reaped.
293-
if err := parent.terminate(); err != nil {
293+
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
294294
logrus.Warn(err)
295295
}
296296
return newSystemErrorWithCause(err, "starting container process")
@@ -316,7 +316,7 @@ func (c *linuxContainer) start(process *Process, isInit bool) error {
316316
}
317317
for i, hook := range c.config.Hooks.Poststart {
318318
if err := hook.Run(s); err != nil {
319-
if err := parent.terminate(); err != nil {
319+
if err := ignoreTerminateErrors(parent.terminate()); err != nil {
320320
logrus.Warn(err)
321321
}
322322
return newSystemErrorWithCausef(err, "running poststart hook %d", i)
@@ -1776,3 +1776,18 @@ func (c *linuxContainer) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Na
17761776

17771777
return bytes.NewReader(r.Serialize()), nil
17781778
}
1779+
1780+
// ignoreTerminateErrors returns nil if the given err matches an error known
1781+
// to indicate that the terminate occurred successfully or err was nil, otherwise
1782+
// err is returned unaltered.
1783+
func ignoreTerminateErrors(err error) error {
1784+
if err == nil {
1785+
return nil
1786+
}
1787+
s := err.Error()
1788+
switch {
1789+
case strings.Contains(s, "process already finished"), strings.Contains(s, "Wait was already called"):
1790+
return nil
1791+
}
1792+
return err
1793+
}

0 commit comments

Comments
 (0)