From 56c8b9269a9bd9c7bb4fbfdd85088ae11c2f1a04 Mon Sep 17 00:00:00 2001 From: "nico.vanelslande" Date: Tue, 31 May 2016 14:51:56 +0100 Subject: [PATCH] Improved resilience of the VirtualBox driver read_used_ports function by ignoring VMs that may have been deleted between the calls to 'vboxmanage list vms' and 'vboxmanage showvminfo' --- plugins/providers/virtualbox/driver/version_4_0.rb | 11 +++++++++-- plugins/providers/virtualbox/driver/version_4_1.rb | 11 +++++++++-- plugins/providers/virtualbox/driver/version_4_2.rb | 11 +++++++++-- plugins/providers/virtualbox/driver/version_4_3.rb | 11 +++++++++-- plugins/providers/virtualbox/driver/version_5_0.rb | 13 ++++++++++--- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_4_0.rb b/plugins/providers/virtualbox/driver/version_4_0.rb index 66e9a37be..7c37a69b7 100644 --- a/plugins/providers/virtualbox/driver/version_4_0.rb +++ b/plugins/providers/virtualbox/driver/version_4_0.rb @@ -422,8 +422,15 @@ module VagrantPlugins # Ignore our own used ports next if uuid == @uuid - read_forwarded_ports(uuid, true).each do |_, _, hostport, _| - ports << hostport + begin + read_forwarded_ports(uuid, true).each do |_, _, hostport, _| + ports << hostport + end + rescue Vagrant::Errors::VBoxManageError => e + raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND") + + # VirtualBox could not find the vm. It may have been deleted + # by another process after we called 'vboxmanage list vms'? Ignore this error. end end end diff --git a/plugins/providers/virtualbox/driver/version_4_1.rb b/plugins/providers/virtualbox/driver/version_4_1.rb index 79f4174ad..9093dc16a 100644 --- a/plugins/providers/virtualbox/driver/version_4_1.rb +++ b/plugins/providers/virtualbox/driver/version_4_1.rb @@ -525,8 +525,15 @@ module VagrantPlugins # Ignore our own used ports next if uuid == @uuid - read_forwarded_ports(uuid, true).each do |_, _, hostport, _| - ports << hostport + begin + read_forwarded_ports(uuid, true).each do |_, _, hostport, _| + ports << hostport + end + rescue Vagrant::Errors::VBoxManageError => e + raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND") + + # VirtualBox could not find the vm. It may have been deleted + # by another process after we called 'vboxmanage list vms'? Ignore this error. end end end diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index 6ece1d91e..de2c46dad 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -458,8 +458,15 @@ module VagrantPlugins # Ignore our own used ports next if uuid == @uuid - read_forwarded_ports(uuid, true).each do |_, _, hostport, _| - ports << hostport + begin + read_forwarded_ports(uuid, true).each do |_, _, hostport, _| + ports << hostport + end + rescue Vagrant::Errors::VBoxManageError => e + raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND") + + # VirtualBox could not find the vm. It may have been deleted + # by another process after we called 'vboxmanage list vms'? Ignore this error. end end end diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 4f2caccf8..ce125625c 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -569,8 +569,15 @@ module VagrantPlugins # Ignore our own used ports next if uuid == @uuid - read_forwarded_ports(uuid, true).each do |_, _, hostport, _| - ports << hostport + begin + read_forwarded_ports(uuid, true).each do |_, _, hostport, _| + ports << hostport + end + rescue Vagrant::Errors::VBoxManageError => e + raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND") + + # VirtualBox could not find the vm. It may have been deleted + # by another process after we called 'vboxmanage list vms'? Ignore this error. end end end diff --git a/plugins/providers/virtualbox/driver/version_5_0.rb b/plugins/providers/virtualbox/driver/version_5_0.rb index 7c5b9f16f..b77a5dc29 100644 --- a/plugins/providers/virtualbox/driver/version_5_0.rb +++ b/plugins/providers/virtualbox/driver/version_5_0.rb @@ -567,9 +567,16 @@ module VagrantPlugins # Ignore our own used ports next if uuid == @uuid - read_forwarded_ports(uuid, true).each do |_, _, hostport, _, hostip| - hostip = '*' if hostip.nil? || hostip.empty? - used_ports[hostport].add?(hostip) + begin + read_forwarded_ports(uuid, true).each do |_, _, hostport, _, hostip| + hostip = '*' if hostip.nil? || hostip.empty? + used_ports[hostport].add?(hostip) + end + rescue Vagrant::Errors::VBoxManageError => e + raise if !e.extra_data[:stderr].include?("VBOX_E_OBJECT_NOT_FOUND") + + # VirtualBox could not find the vm. It may have been deleted + # by another process after we called 'vboxmanage list vms'? Ignore this error. end end end