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

Add at_exit block automatically #397

Merged
merged 30 commits into from
May 18, 2018
Merged

Add at_exit block automatically #397

merged 30 commits into from
May 18, 2018

Conversation

Cawllec
Copy link
Contributor

@Cawllec Cawllec commented Nov 20, 2017

Adds a configuration options and method to register a pre-defined at_exit block when configuration is run.

  • register_at_exit function accessible on library to add at_exit block with severity reasoning included
  • add_exit_handler configuration option automatically calls register_at_exit if set to true, and is flagged to only do so once
  • add_exit_handler defaults to false to avoid issues in frameworks (for instance can block exit 1 signals in rails)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.4%) to 76.422% when pulling 46e2b07 on cawllec/auto_at_exit into 7323b6a on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 76.732% when pulling 8eb7bcc on cawllec/auto_at_exit into 7323b6a on master.

Copy link
Contributor

@snmaynard snmaynard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Questions

  1. Does this fire in a normal rails app? Presumably we trap and register the ctrl-c on kill
  2. Why does this use a separate flag to auto_notify. Other notifiers hook into that flag.

lib/bugsnag.rb Outdated
@@ -114,6 +120,21 @@ def notify(exception, auto_notify=false, &block)
end
end

# Registers an at_exit function to automatically catch errors on exit
# This can disable by setting the 'add_exit_handler' option to False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be disabled by setting the 'add_exit_handler' option to false

@Cawllec
Copy link
Contributor Author

Cawllec commented Nov 20, 2017

I put it on a separate config option as at_exit blocks can interfere with exit codes. I didn't think it was a good idea to have at_exit blocks being registered automatically if users just want the rails/other framework exception hooks working.

I don't believe it captures the kill signal, but I'm not sure it won't spit out the last exception in the app, even if it's been captured and dealt with already. I'll test this tomorrow.

@snmaynard
Copy link
Contributor

I'm pretty sure it will capture kill

@snmaynard
Copy link
Contributor

It doesnt look like the code here will alter the exit code?

@Cawllec
Copy link
Contributor Author

Cawllec commented Nov 21, 2017

From my testing it doesn't capture kill signals in the example rails apps. Nor does it re-send the previous error if it's already been handled. Rather than linking it to auto_notify I'd rather have it opt-out, but still separate.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.7%) to 77.559% when pulling f1c1190 on cawllec/auto_at_exit into 7323b6a on master.

@snmaynard
Copy link
Contributor

Why? Python links it to auto_notify. Why the difference?

@Cawllec
Copy link
Contributor Author

Cawllec commented Nov 22, 2017

The main difference is that this change could potentially be considered "breaking" for users who're already using custom at_exit blocks which we've advised users to do in the documentation to this point.
If there's already an at_exit error handler in place it will be sending two error notifications per exit than one.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 76.836% when pulling 63499c1 on cawllec/auto_at_exit into 7323b6a on master.

@snmaynard
Copy link
Contributor

How does it sound to put it behind a separate flag for now but when we do a major version bump we make a change to make it consistent with python? I like consistency across the notifiers because it makes support and integration easier for users.

@Cawllec
Copy link
Contributor Author

Cawllec commented Feb 8, 2018

Provided @duncanhewett is happy with the documentation I'd like to get this merged and released.
Following face to face with @snmaynard, this would be a good candidate for new integration tests.

@snmaynard
Copy link
Contributor

I would prefer to bump to v7 and make the at_exit block gated by auto_notify and on by default.

@Cawllec
Copy link
Contributor Author

Cawllec commented Feb 8, 2018

I'd be happy with that, I'll have a look at what other changes could be made at the same time.

@Cawllec
Copy link
Contributor Author

Cawllec commented Feb 8, 2018

Tests appear to be failing on this due to travis issues with Jruby. It installs and runs through tests fine locally.

lib/bugsnag.rb Outdated
@@ -126,6 +124,40 @@ def notify(exception, auto_notify=false, &block)
end
end

##
# Registers an at_exit function to automatically catch errors on exit
# This can be disabled by setting the 'add_exit_handler' configuration option to false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is outdated now

@Cawllec
Copy link
Contributor Author

Cawllec commented Mar 29, 2018

Can I get a re-review on this @snmaynard?

@snmaynard
Copy link
Contributor

I pushed a cleanup commit to this branch addressing my review comments.

@Cawllec Cawllec changed the base branch from master to next May 11, 2018 13:18
@Cawllec
Copy link
Contributor Author

Cawllec commented May 11, 2018

Thanks for that. For CI: Rubocop is complaining about module length - I would suggest again bumping up the module limit size and bringing forward a planned refactor.

@kattrali kattrali merged commit 042ed6f into next May 18, 2018
@kattrali kattrali deleted the cawllec/auto_at_exit branch May 18, 2018 06:02
mrnugget added a commit to mrnugget/bugsnag-ruby that referenced this pull request Jul 20, 2018
The previous behaviour resulted in applications reporting errors even
though they were gracefully and without any problems shut down. Example:
the puma webserver relies on `SIGTERM` to gracefully shut down its
workers and Bugsnag reported errors when it was normally shut down.

For more information on puma's behaviour, see here:

    puma/puma#1438

With the `at_exit` handler introduced in bugsnag#397, Bugsnag would catch
`SignalExceptions` on exit and report them as error, even though they
are none.

This PR changes the existing behaviour to add `SignalException` as a
special case in which the exception should not be passed to
`Bugsnag.notify`.

Due to the Ruby exiting when a `SignalException` is raised I had to
refactor the code to make the actual handling of the exit-exceptions
testable without the test suite quitting.
tobyhs added a commit that referenced this pull request Aug 1, 2018
With #397 we receive SignalException error reports when puma shuts down,
which aren't really errors.
kattrali pushed a commit that referenced this pull request Nov 14, 2018
* Add SignalException to default ignore_classes

With #397 we receive SignalException error reports when puma shuts down,
which aren't really errors.

* Remove exit exception checks in integrations

These are now in the default ignore_classes.

* Improve IgnoredExceptions: Remove exception rejection from sidekiq integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants