From 7e47602e3d43db541dd65c019e512f72f2dd6d2b Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 12 Feb 2019 16:05:14 -0800 Subject: [PATCH] Wrap output in thread when being called from within trap-context This prevents a ThreadError exception being raised on sigint which resulted in a stacktrace being dumped. --- lib/vagrant/action/runner.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/action/runner.rb b/lib/vagrant/action/runner.rb index fb70fa317..6eb185f97 100644 --- a/lib/vagrant/action/runner.rb +++ b/lib/vagrant/action/runner.rb @@ -66,11 +66,29 @@ module Vagrant ui = environment[:ui] if environment.key?(:ui) int_callback = lambda do if environment[:interrupted] - ui.error I18n.t("vagrant.actions.runner.exit_immediately") if ui + if ui + begin + ui.error I18n.t("vagrant.actions.runner.exit_immediately") + rescue ThreadError + # We're being called in a trap-context. Wrap in a thread. + Thread.new { + ui.error I18n.t("vagrant.actions.runner.exit_immediately") + }.join(THREAD_MAX_JOIN_TIMEOUT) + end + end abort end - ui.warn I18n.t("vagrant.actions.runner.waiting_cleanup") if ui && !@@reported_interrupt + if ui && !@@reported_interrupt + begin + ui.warn I18n.t("vagrant.actions.runner.waiting_cleanup") + rescue ThreadError + # We're being called in a trap-context. Wrap in a thread. + Thread.new { + ui.warn I18n.t("vagrant.actions.runner.waiting_cleanup") + }.join(THREAD_MAX_JOIN_TIMEOUT) + end + end environment[:interrupted] = true @@reported_interrupt = true end