core: retry acquire of dotlock [GH-3735]

This commit is contained in:
Mitchell Hashimoto 2014-05-09 10:28:37 -07:00
parent 2a973df440
commit 9c684ad2b7
2 changed files with 12 additions and 5 deletions

View File

@ -19,6 +19,8 @@ BUG FIXES:
- core: Don't lock machines on SSH actions. [GH-3664]
- core: Fixed crash when adding a box from Vagrant Cloud that was the
same name as a real directory. [GH-3732]
- core: Parallelization is more stable, doesn't crash due to to
bad locks. [GH-3735]
- provisioners/shell: Fix shell provisioner config validation when the
`binary` option is set to false [GH-3712]
- providers/docker: default proxy VM won't use HGFS [GH-3687]

View File

@ -403,17 +403,22 @@ module Vagrant
lock_path = data_dir.join("lock.#{name}.lock")
@logger.debug("Attempting to acquire process-lock: #{name}")
lock("dotlock", noop: name == "dotlock") do
lock("dotlock", noop: name == "dotlock", retry: true) do
f = File.open(lock_path, "w+")
end
# The file locking fails only if it returns "false." If it
# succeeds it returns a 0, so we must explicitly check for
# the proper error case.
if f.flock(File::LOCK_EX | File::LOCK_NB) === false
while f.flock(File::LOCK_EX | File::LOCK_NB) === false
@logger.warn("Process-lock in use: #{name}")
raise Errors::EnvironmentLockedError,
name: name
if !opts[:retry]
raise Errors::EnvironmentLockedError,
name: name
end
sleep 0.2
end
@logger.info("Acquired process lock: #{name}")
@ -434,7 +439,7 @@ module Vagrant
# Clean up the lock file, this requires another lock
if name != "dotlock"
lock("dotlock") do
lock("dotlock", retry: true) do
f.close
File.delete(lock_path)
end