Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore SIGTERM signal exceptions. #269

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Added the ability to halt notices in callbacks using `notice.halt!`

### Fixed
- Ignore SIGTERM SignalExceptions.

## [3.3.0] - 2018-01-29
### Changed
Expand Down
9 changes: 8 additions & 1 deletion lib/honeybadger/singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def load_plugins!
# @api private
def install_at_exit_callback
at_exit do
if $! && !$!.is_a?(SystemExit) && Honeybadger.config[:'exceptions.notify_at_exit']
if $! && !ignored_exception?($!) && Honeybadger.config[:'exceptions.notify_at_exit']
Honeybadger.notify($!, component: 'at_exit', sync: true)
end

Expand All @@ -85,4 +85,11 @@ def start(config = {})
end
WARNING
end

private
# @api private
def ignored_exception?(exception)
exception.is_a?(SystemExit) ||
(exception.is_a?(SignalException) && exception.signm == "SIGTERM")
end
end
19 changes: 19 additions & 0 deletions spec/features/at_exit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
feature "Rescuing exceptions at exit" do
let(:crash_cmd) { "ruby #{ FIXTURES_PATH.join('ruby_crash.rb') }" }

def custom_crash_cmd(crash_type)
"ruby #{ FIXTURES_PATH.join('ruby_custom_crash.rb') } #{ crash_type }"
end

before do
set_environment_variable('HONEYBADGER_API_KEY', 'asdf')
set_environment_variable('HONEYBADGER_LOGGING_LEVEL', 'DEBUG')
Expand All @@ -11,6 +15,21 @@
assert_notification('error' => {'class' => 'RuntimeError', 'message' => 'RuntimeError: badgers!'})
end

it "ignores SystemExit" do
expect(run(custom_crash_cmd("system_exit"))).not_to be_successfully_executed
assert_no_notification
end

it "ignores SignalException of type SIGTERM" do
expect(run(custom_crash_cmd("sigterm"))).not_to be_successfully_executed
assert_no_notification
end

it "reports SignalException of type other than SIGTERM" do
expect(run(custom_crash_cmd("hup"))).not_to be_successfully_executed
assert_notification('error' => {'class' => 'SignalException', 'message' => 'SignalException: SIGHUP'})
end

context "at_exit is disabled" do
before do
set_environment_variable('HONEYBADGER_EXCEPTIONS_NOTIFY_AT_EXIT', 'false')
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/ruby_custom_crash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'honeybadger'

CRASHES = {
"system_exit" => ->{ exit -1 },
"sigterm" => ->{ raise SignalException, "TERM" },
"hup" => ->{ raise SignalException, "HUP" },
}

crash_type = ARGV.first || (raise "Invalid argument")

(CRASHES[crash_type] || ->{ raise "Invalid crash type" }).()