Fix race condition in recreate containers

Container might have stopped between checking `is_running` and
calling `stop()`, which then threw an exception.

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
This commit is contained in:
Ben Firshman 2014-07-11 14:52:47 -07:00
commit b573b87a92
2 changed files with 27 additions and 7 deletions

View file

@ -177,8 +177,15 @@ class Service(object):
return tuples
def recreate_container(self, container, **override_options):
if container.is_running:
try:
container.stop(timeout=1)
except APIError as e:
if (e.response.status_code == 500
and e.explanation
and 'no such process' in str(e.explanation)):
pass
else:
raise
intermediate_container = Container.create(
self.client,