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
Handle panic at endpoint #458
Conversation
cac6fa3
to
5a4accb
Compare
I finally added UTs... |
codegen/templates/endpoint.tmpl
Outdated
zap.String("stacktrace", stacktrace), | ||
zap.String("endpoint", h.endpoint.EndpointName)) | ||
|
||
res.SendError(502, "Unexpected workflow panic, recovered at endpoint.", e) |
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.
You should probably not send the error to the client. The error may have debug or sensitive information.
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.
fixed
ctx context.Context, | ||
headers zanzibar.Header, | ||
) (string, zanzibar.Header, error) { | ||
defer func() { |
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.
You don't need to defer
this. Just call panic()
directly.
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.
fixed
if r := recover(); r != nil { | ||
stacktrace := string(debug.Stack()) | ||
e := errors.Errorf("enpoint panic: %v, stacktrace: %v", r, stacktrace) | ||
h.Dependencies.Default.ContextLogger.Error( |
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.
Can you also increment a specific metric for panics so we can add alerting on specifically panics?
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.
fixed
h.endpointScope.Counter("endpoint.panic").Inc(1) | ||
isSuccessful = false | ||
response = nil | ||
headers = map[string]string{} |
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.
nit: do we want to preserve some header information if any
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.
return nil instead of empty, this is the same behavior https://github.com/uber/zanzibar/pull/458/files/ef542b0b5925a2d569a7fc6d424379c6d39ff036#diff-7c8f7ec39bf077182fa0b404b3d49d76R124 when other error happens
@@ -54,6 +58,9 @@ func NewBarArgNotStructHandler(deps *module.Dependencies) *BarArgNotStructHandle | |||
"bar", "argNotStruct", | |||
handler.HandleRequest, | |||
) | |||
handler.endpointScope = deps.Default.Scope.Tagged(map[string]string{ |
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.
let's just reuse this scope: https://github.com/uber/zanzibar/blob/master/runtime/router.go#L70
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.
fixed
not sure why build and coverage not showing as the gate. However, I can see it is already passed the build |
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.
pending on another stamp from jacobg
thank you for review |
This commits