From a75b14b7694e50aed37c7aa134cf9a027c181bd4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Nov 2015 11:19:56 -0800 Subject: [PATCH] providers/virtualbox: wrap version set in mutex --- plugins/providers/virtualbox/driver/meta.rb | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/providers/virtualbox/driver/meta.rb b/plugins/providers/virtualbox/driver/meta.rb index 668659fe8..7aceb9fca 100644 --- a/plugins/providers/virtualbox/driver/meta.rb +++ b/plugins/providers/virtualbox/driver/meta.rb @@ -1,4 +1,5 @@ require "forwardable" +require "thread" require "log4r" @@ -20,6 +21,7 @@ module VagrantPlugins # We cache the read VirtualBox version here once we have one, # since during the execution of Vagrant, it likely doesn't change. @@version = nil + @@version_lock = Mutex.new # The UUID of the virtual machine we represent attr_reader :uuid @@ -36,16 +38,18 @@ module VagrantPlugins @logger = Log4r::Logger.new("vagrant::provider::virtualbox::meta") @uuid = uuid - if !@@version - # Read and assign the version of VirtualBox we know which - # specific driver to instantiate. - begin - @@version = read_version - rescue Vagrant::Errors::CommandUnavailable, - Vagrant::Errors::CommandUnavailableWindows - # This means that VirtualBox was not found, so we raise this - # error here. - raise Vagrant::Errors::VirtualBoxNotDetected + @@version_lock.synchronize do + if !@@version + # Read and assign the version of VirtualBox we know which + # specific driver to instantiate. + begin + @@version = read_version + rescue Vagrant::Errors::CommandUnavailable, + Vagrant::Errors::CommandUnavailableWindows + # This means that VirtualBox was not found, so we raise this + # error here. + raise Vagrant::Errors::VirtualBoxNotDetected + end end end