diff --git a/lib/async/container/controller.rb b/lib/async/container/controller.rb index 8e6e587..e68ff20 100644 --- a/lib/async/container/controller.rb +++ b/lib/async/container/controller.rb @@ -135,18 +135,20 @@ def restart raise SetupError, container end - # Make this swap as atomic as possible: + # The following swap should be atomic: old_container = @container @container = container + container = nil + + if old_container + Console.logger.debug(self, "Stopping old container...") + old_container&.stop + end - Console.logger.debug(self, "Stopping old container...") - old_container&.stop @notify&.ready! - rescue + ensure # If we are leaving this function with an exception, try to kill the container: container&.stop(false) - - raise end # Reload the existing container. Children instances will be reloaded using `SIGHUP`.