-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
When the App stops, the ctx in the afterStop callback is not available #3226
Comments
你好 @shuqingzai! 我是 Dosu,一个可以帮助解决bug、回答问题并成为贡献者的机器人。我在这里可以为你提供帮助,同时等待人类维护者的回复。我会立即查看你的问题,并尽快给你一个完整的回答。 |
Hello @shuqingzai! I'm Dosu, a bot that can help solve bugs, answer questions, and become a contributor. I'm here to help you while I wait to hear back from the human maintainers. I will review your question immediately and give you a complete answer as soon as possible. |
Based on your description, it seems like you're encountering an issue where the You're correct in your suggestion that the In the current implementation of the sctx := NewContext(a.ctx, a)
...
for _, fn := range a.opts.afterStop {
err = fn(sctx)
} To ensure that // Right before executing afterStop functions
oCtxBased := NewContext(a.opts.ctx, a) // Using o.ctx from options to create a new context
for _, fn := range a.opts.afterStop {
err = fn(oCtxBased) // Pass the new context based on o.ctx
} This modification ensures that the As for the role of I hope this helps! If you have any further questions, feel free to ask. Sources
|
What happened:
afterStopFn
接收基于 App 的ctx
衍生的sctx
, 但是在接收停止信号时,就会取消 App 的ctx
,导致sctx
也会被取消,afterStopFn
无法执行(如:需要推送系统停止的消息等)参考:
kratos/app.go
Line 144 in 50cad79
kratos/app.go
Line 166 in 50cad79
是否应该像
stopSrv
的方式,可设置应用停止后,回调函数可设置执行超时,基于o.ctx
创建,不依赖 App.ctx ??kratos/app.go
Line 105 in 50cad79
What you expected to happen:
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
Environment:
kratos -v
):go version
):cat /etc/os-release
):The text was updated successfully, but these errors were encountered: