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

Handle panic at endpoint #458

Merged
merged 6 commits into from Sep 13, 2018
Merged

Handle panic at endpoint #458

merged 6 commits into from Sep 13, 2018

Conversation

herainman
Copy link
Contributor

@herainman herainman commented Sep 6, 2018

This commits

  • add defer function and endpoint.tmpl and tchannel_endpoint.tmpl which handles all the panic at endpoint level
  • add UTs both for HTTP and Tchannel request for this change

@coveralls
Copy link

coveralls commented Sep 6, 2018

Coverage Status

Coverage increased (+5.3%) to 67.885% when pulling ef5a7cc on xuantest2 into ad19f7b on master.

@herainman herainman force-pushed the xuantest2 branch 2 times, most recently from cac6fa3 to 5a4accb Compare September 6, 2018 22:54
@herainman
Copy link
Contributor Author

I finally added UTs...

zap.String("stacktrace", stacktrace),
zap.String("endpoint", h.endpoint.EndpointName))

res.SendError(502, "Unexpected workflow panic, recovered at endpoint.", e)
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

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(
Copy link
Contributor

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?

Copy link
Contributor Author

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{}
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -54,6 +58,9 @@ func NewBarArgNotStructHandler(deps *module.Dependencies) *BarArgNotStructHandle
"bar", "argNotStruct",
handler.HandleRequest,
)
handler.endpointScope = deps.Default.Scope.Tagged(map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@herainman
Copy link
Contributor Author

herainman commented Sep 10, 2018

not sure why build and coverage not showing as the gate.

However, I can see it is already passed the build

Copy link
Contributor

@cl1337 cl1337 left a 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

@herainman
Copy link
Contributor Author

thank you for review

@herainman herainman merged commit ab6682b into master Sep 13, 2018
@ChuntaoLu ChuntaoLu deleted the xuantest2 branch October 1, 2018 18:44
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