From 8d46b09a116ccd42875c077f6c03e40f48f5ca18 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Wed, 13 Jul 2022 14:04:32 -0500 Subject: [PATCH] Fix Docker machines being lost in go side By pruning machines that are in "unknown" status after each operation, the Go code path exposed the fact that the Docker provider was not updating the machine index during an "up" - leaving the state as "unknown". This is basically a bug within the Docker provider, so I think it's okay to update the plugin code to correct this rather than working around the issue in Go. All we need to do is call `machine.state` instead of reaching through to `machine.provider.state` while waiting for the container to be started. That causes the extra logic for updating the machine index in `machine.state` to fire. --- plugins/providers/docker/action/wait_for_running.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/providers/docker/action/wait_for_running.rb b/plugins/providers/docker/action/wait_for_running.rb index 89164ddcb..479af8a14 100644 --- a/plugins/providers/docker/action/wait_for_running.rb +++ b/plugins/providers/docker/action/wait_for_running.rb @@ -16,8 +16,10 @@ module VagrantPlugins wait = true if !machine.provider_config.remains_running + @logger.debug("remains_running is false") wait = false - elsif machine.provider.state.id == :running + elsif machine.state.id == :running + @logger.debug("container is already running") wait = false end @@ -28,7 +30,7 @@ module VagrantPlugins # First, make sure it leaves the stopped state if its supposed to. after = sleeper(5) - while machine.provider.state.id == :stopped + while machine.state.id == :stopped if after[:done] raise Errors::StateStopped end @@ -38,7 +40,7 @@ module VagrantPlugins # Then, wait for it to become running after = sleeper(30) while true - state = machine.provider.state + state = machine.state break if state.id == :running @logger.info("Waiting for container to run. State: #{state.id}")