Merge pull request #9485 from vrothberg/fix-9479
container removal: handle already removed containers
This commit is contained in:
		
						commit
						ca0af71bef
					
				|  | @ -954,18 +954,22 @@ func (c *Container) removeAllExecSessions() error { | ||||||
| 	} | 	} | ||||||
| 	// Delete all exec sessions
 | 	// Delete all exec sessions
 | ||||||
| 	if err := c.runtime.state.RemoveContainerExecSessions(c); err != nil { | 	if err := c.runtime.state.RemoveContainerExecSessions(c); err != nil { | ||||||
| 		if lastErr != nil { | 		if errors.Cause(err) != define.ErrCtrRemoved { | ||||||
| 			logrus.Errorf("Error stopping container %s exec sessions: %v", c.ID(), lastErr) | 			if lastErr != nil { | ||||||
|  | 				logrus.Errorf("Error stopping container %s exec sessions: %v", c.ID(), lastErr) | ||||||
|  | 			} | ||||||
|  | 			lastErr = err | ||||||
| 		} | 		} | ||||||
| 		lastErr = err |  | ||||||
| 	} | 	} | ||||||
| 	c.state.ExecSessions = nil | 	c.state.ExecSessions = nil | ||||||
| 	c.state.LegacyExecSessions = nil | 	c.state.LegacyExecSessions = nil | ||||||
| 	if err := c.save(); err != nil { | 	if err := c.save(); err != nil { | ||||||
| 		if lastErr != nil { | 		if errors.Cause(err) != define.ErrCtrRemoved { | ||||||
| 			logrus.Errorf("Error stopping container %s exec sessions: %v", c.ID(), lastErr) | 			if lastErr != nil { | ||||||
|  | 				logrus.Errorf("Error stopping container %s exec sessions: %v", c.ID(), lastErr) | ||||||
|  | 			} | ||||||
|  | 			lastErr = err | ||||||
| 		} | 		} | ||||||
| 		lastErr = err |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return lastErr | 	return lastErr | ||||||
|  |  | ||||||
|  | @ -319,12 +319,18 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, | ||||||
| 
 | 
 | ||||||
| 	errMap, err := parallelctr.ContainerOp(ctx, ctrs, func(c *libpod.Container) error { | 	errMap, err := parallelctr.ContainerOp(ctx, ctrs, func(c *libpod.Container) error { | ||||||
| 		err := ic.Libpod.RemoveContainer(ctx, c, options.Force, options.Volumes) | 		err := ic.Libpod.RemoveContainer(ctx, c, options.Force, options.Volumes) | ||||||
| 		if err != nil { | 		if err == nil { | ||||||
| 			if options.Ignore && errors.Cause(err) == define.ErrNoSuchCtr { | 			return nil | ||||||
|  | 		} | ||||||
|  | 		logrus.Debugf("Failed to remove container %s: %s", c.ID(), err.Error()) | ||||||
|  | 		switch errors.Cause(err) { | ||||||
|  | 		case define.ErrNoSuchCtr: | ||||||
|  | 			if options.Ignore { | ||||||
| 				logrus.Debugf("Ignoring error (--allow-missing): %v", err) | 				logrus.Debugf("Ignoring error (--allow-missing): %v", err) | ||||||
| 				return nil | 				return nil | ||||||
| 			} | 			} | ||||||
| 			logrus.Debugf("Failed to remove container %s: %s", c.ID(), err.Error()) | 		case define.ErrCtrRemoved: | ||||||
|  | 			return nil | ||||||
| 		} | 		} | ||||||
| 		return err | 		return err | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
|  | @ -51,6 +51,13 @@ load helpers | ||||||
|     run_podman rm $rand $external_cid |     run_podman rm $rand $external_cid | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @test "podman rm <-> run --rm race" { | ||||||
|  |     # A container's lock is released before attempting to stop it.  This opens | ||||||
|  |     # the window for race conditions that led to #9479. | ||||||
|  |     run_podman run --rm -d $IMAGE sleep infinity | ||||||
|  |     run_podman rm -af | ||||||
|  | } | ||||||
|  | 
 | ||||||
| # I'm sorry! This test takes 13 seconds. There's not much I can do about it, | # I'm sorry! This test takes 13 seconds. There's not much I can do about it, | ||||||
| # please know that I think it's justified: podman 1.5.0 had a strange bug | # please know that I think it's justified: podman 1.5.0 had a strange bug | ||||||
| # in with exit status was not preserved on some code paths with 'rm -f' | # in with exit status was not preserved on some code paths with 'rm -f' | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue