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

Changing recovery function can cause panic #52

Closed
eapache opened this issue Nov 12, 2013 · 2 comments · Fixed by #186
Closed

Changing recovery function can cause panic #52

eapache opened this issue Nov 12, 2013 · 2 comments · Fixed by #186

Comments

@eapache
Copy link
Contributor

eapache commented Nov 12, 2013

@fw42 just thought of this. Set the handler, do something that spawns a go routine, then set the handler to nil. A panic would cause a second panic when trying to call a nil function pointer.

Always defer the function, then do the nil check inside the deferred function seems like the fix? There's still a race there, but dunno how to fix that, and it's really unlikely.

fw42 pushed a commit that referenced this issue Nov 13, 2013
@fw42
Copy link
Contributor

fw42 commented Nov 13, 2013

I guess we could fix it once and for all by having a SetPanicHandler method with a mutex, but that seems a bit overkill for such an unlikely use-case.

fw42 added a commit that referenced this issue Nov 13, 2013
@fw42 fw42 closed this as completed Nov 13, 2013
@eapache
Copy link
Contributor Author

eapache commented Nov 13, 2013

Agreed. And it is still technically an error case (since some panic has to trigger the callback) so the worst case is that we don't get a useful backtrace from the panic.

eapache added a commit that referenced this issue Nov 15, 2014
Properly fixes #52 this time.

Almost exactly a year ago (+ 3 days) when Flo added the withRecover function we
discussed how if the user set/unset the PanicHandler in time with an actual
panic they could cause secondary panics and weirdness. We decided putting a
mutex in was overkill and closed the issue.

It just occured to me that there is a 1000x better fix, which is to just cache
the handler value locally so we know we're calling the same value we do our
nil-check on. Duh. I'm not sure why neither of us thought of this at the time...
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 a pull request may close this issue.

2 participants