mirror of https://github.com/containers/podman.git
Merge pull request #17022 from mheon/fix_defer_locking
Fix a potential defer logic error around locking
This commit is contained in:
commit
c83a2f8a0a
|
|
@ -85,6 +85,15 @@ func (c *Container) Init(ctx context.Context, recursive bool) error {
|
||||||
func (c *Container) Start(ctx context.Context, recursive bool) (finalErr error) {
|
func (c *Container) Start(ctx context.Context, recursive bool) (finalErr error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if finalErr != nil {
|
if finalErr != nil {
|
||||||
|
// Have to re-lock.
|
||||||
|
// As this is the first defer, it's the last thing to
|
||||||
|
// happen in the function - so `defer c.lock.Unlock()`
|
||||||
|
// below already fired.
|
||||||
|
if !c.batched {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
if err := saveContainerError(c, finalErr); err != nil {
|
if err := saveContainerError(c, finalErr); err != nil {
|
||||||
logrus.Debug(err)
|
logrus.Debug(err)
|
||||||
}
|
}
|
||||||
|
|
@ -125,6 +134,15 @@ func (c *Container) Update(res *spec.LinuxResources) error {
|
||||||
func (c *Container) StartAndAttach(ctx context.Context, streams *define.AttachStreams, keys string, resize <-chan resize.TerminalSize, recursive bool) (retChan <-chan error, finalErr error) {
|
func (c *Container) StartAndAttach(ctx context.Context, streams *define.AttachStreams, keys string, resize <-chan resize.TerminalSize, recursive bool) (retChan <-chan error, finalErr error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if finalErr != nil {
|
if finalErr != nil {
|
||||||
|
// Have to re-lock.
|
||||||
|
// As this is the first defer, it's the last thing to
|
||||||
|
// happen in the function - so `defer c.lock.Unlock()`
|
||||||
|
// below already fired.
|
||||||
|
if !c.batched {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
if err := saveContainerError(c, finalErr); err != nil {
|
if err := saveContainerError(c, finalErr); err != nil {
|
||||||
logrus.Debug(err)
|
logrus.Debug(err)
|
||||||
}
|
}
|
||||||
|
|
@ -212,6 +230,15 @@ func (c *Container) Stop() error {
|
||||||
func (c *Container) StopWithTimeout(timeout uint) (finalErr error) {
|
func (c *Container) StopWithTimeout(timeout uint) (finalErr error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if finalErr != nil {
|
if finalErr != nil {
|
||||||
|
// Have to re-lock.
|
||||||
|
// As this is the first defer, it's the last thing to
|
||||||
|
// happen in the function - so `defer c.lock.Unlock()`
|
||||||
|
// below already fired.
|
||||||
|
if !c.batched {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
if err := saveContainerError(c, finalErr); err != nil {
|
if err := saveContainerError(c, finalErr); err != nil {
|
||||||
logrus.Debug(err)
|
logrus.Debug(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue