core: BatchAction should handle forks [GH-2756]

This commit is contained in:
Mitchell Hashimoto 2014-01-08 21:36:24 -08:00
parent 680f6c1e69
commit 9649712fce
2 changed files with 30 additions and 2 deletions

View File

@ -43,6 +43,8 @@ BUG FIXES:
for the first time, it would get swallowed. It is properly raised now.
- core: Plugin installation does not fail if your local gemrc file has
syntax errors.
- core: Plugins that fork within certain actions will no longer hang
indefinitely. [GH-2756]
- commands/plugin: Plugin installation will fail if dependencies conflict,
rather than at runtime.
- guests/redhat: Set hostname to FQDN, per the documentation for RedHat.

View File

@ -59,15 +59,41 @@ module Vagrant
thread = Thread.new do
Thread.current[:error] = nil
# Record our pid when we started in order to figure out if
# we've forked...
start_pid = Process.pid
begin
machine.send(:action, action, options)
rescue Exception => e
# If we're not parallelizing, then raise the error
raise if !par
# If we're not parallelizing, then raise the error. We also
# don't raise the error if we've forked, because it'll hang
# the process.
raise if !par && Process.pid == start_pid
# Store the exception that will be processed later
Thread.current[:error] = e
end
# If we forked during the process run, we need to do a hard
# exit here. Ruby's fork only copies the running process (which
# would be us), so if we return from this thread, it results
# in a zombie Ruby process.
if Process.pid != start_pid
# We forked.
exit_status = true
if Thread.current[:error]
# We had an error, print the stack trace and exit immediately.
exit_status = false
error = Thread.current[:error]
@logger.error(error.inspect)
@logger.error(error.message)
@logger.error(error.backtrace.join("\n"))
end
Process.exit!(exit_status)
end
end
# Set some attributes on the thread for later