gogf / gf

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
https://goframe.org
MIT License
11.79k stars 1.61k forks source link

[BUG] A panic occurred during the execution of HTTP Server Hook and was not captured. #3112

Open shuqingzai opened 1 year ago

shuqingzai commented 1 year ago

GF 文档中重点提示,在 HTTP 执行流程参考:异常处理 无需自行对 panic 进行处理,内部会自动处理,但是在使用 HOOK事件回调 特性时,panic 并未得到处理

Hook 处理参考:https://github.com/gogf/gf/blob/afeca8cf9dc8bbb7d0cd12f5ff9066295ab28483/net/ghttp/ghttp_server_handler.go#L113 基本都是调用 https://github.com/gogf/gf/blob/afeca8cf9dc8bbb7d0cd12f5ff9066295ab28483/net/ghttp/ghttp_server_router_hook.go#L66 ,这个方法针对 GF 内置的几个 panic 控制流程的标识符有特殊处理,其他默认往上抛,这会导致使用与文档描述不符

  1. 如果使用的是前置 hook ,后续的所有逻辑都会崩溃,是否可以配置传递 panic回调函数处理 ?如:异常告警、服务监控已经失效,无法很好的管理服务健康
  2. 用户没法自定义响应内容,因为在 hook 出现 panic ,服务只是修改了 httpStatusCode ,直接暴露 panic 内容到客户端,这对于服务健壮性而言,十分危险,参考:https://github.com/gogf/gf/blob/afeca8cf9dc8bbb7d0cd12f5ff9066295ab28483/net/ghttp/ghttp_server_router_hook.go#L88

1. What version of Go and system type/arch are you using?

# -> % go version
go version go1.21.3 darwin/amd64

2. What version of GoFrame are you using?

# -> % gf version
GoFrame CLI Tool v2.5.6, https://goframe.org
GoFrame Version: v2.5.6 in current go.mod

3. Can this issue be re-produced with the latest release?

是的

4. What did you do?

5. What did you expect to see?

6. What did you see instead?

github-actions[bot] commented 10 months ago

Hello @shuqingzai. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it! 你好 @shuqingzai。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。