-
Notifications
You must be signed in to change notification settings - Fork 22
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
#105 - Panic Handlers #273
Conversation
19ed945
to
97ebc22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering how (and why) you have selected the locations to place the defer
. It looks like you have chosen places near the occurrence of panics. But this typically leads to a continuing program flow with undefined results, where the caller has no possibility to identify this case, which basically will lead to further runtime panics. These panics are for sure NOT handled by a panic handler, again, so that you still get panics, but now completely unrelated to the original problem.
Similar to the K8S handling, the defer
should be placed near a resurrection point in a program flow, where typically a loop for request handling is in place to assure the handling of further requests, even if a single single one runs in such a problematic situation (for example, reconcilation loop). Or at least a place, where you can safely ignore the outcome of a called function and continue with a new calculation context.
A defer inside an ìnit function is questionable. If the program initialization fails because of some basic misalignment, it makes no sense to run the process at all.
The Must
versions of functions panic if the non-Must versions return an error.
Placing defers
here is also questionable, because you could directly call the error providing function if you want to deal with failures. The Must version is typically intended to be called in init functions (see above).
Correct. Restricted to panics in the library code.
I would argue that this isn't our concern, but rather the users concern. Optimally we wouldn't
I'm not really sure I understand what your saying here, and how it relates in the context of OCM and
If you feel strongly about this I can remove the
The user still may wish to execute some process or code before continuing with a crash, so I think it is still valid to call the handlers here? |
We'll do a compromise and place handling at certain points only. The rest will be handled in a different manner. The ADR has been accepted by all parties so we'll try to be more in line with that. :) |
@jmickey / @Skarlso / @mandelsoft : Can we please get this clarified this week ? It is a long runner already, and I'd like to see this being finished soon. My take: If the current implementation is done according to the ACD which we all agreed on, than this should go out. |
Right, so the main points are:
|
Please re-review with the new changes.
a510ed3
to
3e8092b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, to find all the places where a regular error return can do the job to avoid panics at all.
One panic should be avoided by refactoring the interface and add an error return value.
If you want I can do this at short notice. There are probably many places involved.
40f7f81
to
b2606b4
Compare
4acaf89
to
bb3253f
Compare
70bb7ef
to
90b053b
Compare
90b053b
to
fd657ce
Compare
@mandelsoft This looks good to me now. :) Thanks for the additions. 👍 |
Feel free to merge at your earliest convenience. :)
What this PR does / why we need it:
Allow lib callers to register panic handlers, and choose decide if panics will continue to cause the code to crash.
A defer function has been added to the call sites where panics are made in the library code. Initially I was trying to follow the references up the stack to see if there were fewer places where a defer could be made, but in the end it made the more sense to place the defer close to the panic itself.
Lib consumers can register their own handlers that matches the
PanicHandler
type -func(interface{})
:By default panics will always log the stacktrace.
Which issue(s) this PR fixes:
Fixes #105