Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO TESTS NEEDED] Do not return from c.stop() before re-locking #9624

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,7 @@ func (c *Container) stop(timeout uint) error {
c.lock.Unlock()
}

if err := c.ociRuntime.StopContainer(c, timeout, all); err != nil {
return err
}
stopErr := c.ociRuntime.StopContainer(c, timeout, all)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you drop a comment here explaining why we must move the error check below the potential Lock(). It's easy to miss and since we can't test, we may silently regress.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


if !c.batched {
c.lock.Lock()
Expand All @@ -1318,13 +1316,23 @@ func (c *Container) stop(timeout uint) error {
// If the container has already been removed (e.g., via
// the cleanup process), there's nothing left to do.
case define.ErrNoSuchCtr, define.ErrCtrRemoved:
return nil
return stopErr
default:
if stopErr != nil {
logrus.Errorf("Error syncing container %s status: %v", c.ID(), err)
return stopErr
}
return err
}
}
}

// We have to check stopErr *after* we lock again - otherwise, we have a
// change of panicing on a double-unlock. Ref: GH Issue 9615
if stopErr != nil {
return stopErr
}

// Since we're now subject to a race condition with other processes who
// may have altered the state (and other data), let's check if the
// state has changed. If so, we should return immediately and log a
Expand Down