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

Throwing panic with recovery continues calling middlewares #1770

Closed
marczahn opened this issue Feb 12, 2019 · 3 comments
Closed

Throwing panic with recovery continues calling middlewares #1770

marczahn opened this issue Feb 12, 2019 · 3 comments

Comments

@marczahn
Copy link

marczahn commented Feb 12, 2019

I found a strange behaviour but maybe it is intended:

I have middleware A and B and C which are chained.
In middleware A all panics are cought with a defer. It calls Next() on the gin.Context
Middleware B throws a panic and thus does not call Next().

What I expect: Middleware C is not called. But actually it is called indeed. Is this supposed to be like this and why?

This is middleware A:

...
defer func() {
	if rc := recover(); rc != nil {
		l.WithField("recover", rc).Error("Panic occured")
		c.JSON(http.StatusInternalServerError, "Internal error")
	}
}()
c.Next()
...
@easonlin404
Copy link
Contributor

would you post your example in more detail?

@jbonzo
Copy link

jbonzo commented Jun 3, 2020

I think you need to incorporate c.Abort into your logic. c.Abort is the only way to signal the chain to stop moving forward.

@marczahn
Copy link
Author

marczahn commented Jun 4, 2020

Ah yes - That makes absolutely sense. The problem doesn't exist anymore. Thanks for this idea - So simple at the end :-)

@marczahn marczahn closed this as completed Jun 4, 2020
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

No branches or pull requests

3 participants