Commit ed33d34f authored by danielsdeleo's avatar danielsdeleo
Browse files

Add termination info to error messages

If no logger is configured, we still want to inform the user that the
process was killed (and how).
parent 4ff2d130
......@@ -154,6 +154,7 @@ module Mixlib
@cwd = nil
@valid_exit_codes = [0]
@terminate_reason = nil
if command_args.last.is_a?(Hash)
......@@ -191,6 +192,7 @@ module Mixlib
# results when the command exited with an unexpected status.
def format_for_exception
msg = ""
msg << "#{@terminate_reason}\n" if @terminate_reason
msg << "---- Begin output of #{command} ----\n"
msg << "STDOUT: #{stdout.strip}\n"
msg << "STDERR: #{stderr.strip}\n"
......@@ -67,7 +67,7 @@ module Mixlib
# read anything it wrote when we killed it
# raise
raise CommandTimeout, "command timed out:\n#{format_for_exception}"
raise CommandTimeout, "Command timed out after #{@execution_time.to_i}s:\n#{format_for_exception}"
......@@ -302,10 +302,12 @@ module Mixlib
def reap_errant_child
return if attempt_reap
@terminate_reason = "Command execeded allowed execution time, killed by TERM signal."
logger.error("Command execeded allowed execution time, sending TERM") if logger
Process.kill(:TERM, @child_pid)
sleep 3
return if attempt_reap
@terminate_reason = "Command execeded allowed execution time, did not respond to TERM. Killed by KILL signal."
logger.error("Command did not exit from TERM, sending KILL") if logger
Process.kill(:KILL, @child_pid)
......@@ -869,7 +869,7 @@ describe Mixlib::ShellOut do
let(:logger) { }
let(:options) { {:timeout => 1, :logger => logger} }
it "should log messages about killing the child process", :focus do
it "should log messages about killing the child process" do
# note: let blocks don't correctly memoize if an exception is raised,
# so can't use executed_cmd
lambda { shell_cmd.run_command}.should raise_error(Mixlib::ShellOut::CommandTimeout)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment