Skip to content

fix(graceful_shutdown): use WithShutdown API in sample - #1133

Open
XiaoFeiASK wants to merge 16 commits into
apache:mainfrom
XiaoFeiASK:xiaofei/fix-graceful-shutdown-sample
Open

fix(graceful_shutdown): use WithShutdown API in sample#1133
XiaoFeiASK wants to merge 16 commits into
apache:mainfrom
XiaoFeiASK:xiaofei/fix-graceful-shutdown-sample

Conversation

@XiaoFeiASK

Copy link
Copy Markdown

变更说明

更新 graceful_shutdown sample,使其使用当前推荐的 dubbo.WithShutdown(...) 配置方式。

该 PR 主要解决 sample 仍使用旧的 graceful_shutdown.Init(...) 初始化方式的问题,并同步更新文档和集成测试说明。

问题原因

graceful_shutdown sample 原先通过 graceful_shutdown.Init(...) 配置优雅停机。

当前 Dubbo-go 推荐通过 dubbo.WithShutdown(...)dubbo.NewInstance(...) 中配置 graceful shutdown。如果 sample 继续保留旧写法,用户容易参考到不推荐的 API,也会和当前文档中的新 API 使用方式不一致。

修复方案

  • graceful_shutdown.Init(...) 替换为 dubbo.WithShutdown(...)
  • 使用 dubbo.NewInstance(...) 创建 Dubbo 实例
  • 通过实例创建 Server,确保 graceful shutdown 配置从 Instance 传递到 Server
  • 补充常用 graceful shutdown 配置项,包括 WithTimeoutWithStepTimeoutWithNotifyTimeoutWithConsumerUpdateWaitTimeWithOfflineRequestWindowTimeout
  • 新增 -notify-timeout server 参数,并同步更新 README / README_CN
  • 更新集成测试流程,使 graceful_shutdown sample 覆盖 Triple 长连接场景下的 graceful shutdown 行为

验证

  • go test ./graceful_shutdown/...
  • git diff --check

Fixes #1132

@Alanxtl

Alanxtl commented Aug 12, 2026

Copy link
Copy Markdown
Member

我们的每一个sample同时也是集成测试
考虑一下怎么加一下集成测试 现在的graceful shutdown确实能够展示使用方法 但是还没有加入行为是否符合预期的判断

@XiaoFeiASK

Copy link
Copy Markdown
Author

我们的每一个sample同时也是集成测试 考虑一下怎么加一下集成测试 现在的graceful shutdown确实能够展示使用方法 但是还没有加入行为是否符合预期的判断

Okay, I will try to add integration test

@XiaoFeiASK
XiaoFeiASK force-pushed the xiaofei/fix-graceful-shutdown-sample branch from a02a773 to bfdc959 Compare August 13, 2026 00:28
@Alanxtl

Alanxtl commented Aug 13, 2026

Copy link
Copy Markdown
Member

集成测试的逻辑别加在 intergrate test里面 就加在代码里面 就用if或者select判断符不符合预期 不符合就panic就行了

Comment thread graceful_shutdown/go-client/cmd/main.go Outdated
Comment thread graceful_shutdown/go-server/cmd/main.go Outdated
@Alanxtl

Alanxtl commented Aug 13, 2026

Copy link
Copy Markdown
Member

our project use import-formatter to format import blocks, that's the reason why ur CI fails. For you, u should

  1. run go install github.com/dubbogo/tools/cmd/imports-formatter@latest
  2. cd to the root dir of dubbo-go-samples
  3. run imports-formatter

@XiaoFeiASK

Copy link
Copy Markdown
Author

我们项目使用 import-formatter 来格式化导入块,这就是你的 CI 失败的原因。对你来说,你应该

  1. 运行 go install github.com/dubbogo/tools/cmd/imports-formatter@latest
  2. 切换到 dubbo-go-samples 的根目录
  3. 运行 imports-formatter

ok,thanks for your review

Comment thread graceful_shutdown/go-server/cmd/main.go Outdated
@XiaoFeiASK
XiaoFeiASK force-pushed the xiaofei/fix-graceful-shutdown-sample branch 2 times, most recently from 8c39294 to 47f6da1 Compare August 14, 2026 19:49
@XiaoFeiASK
XiaoFeiASK force-pushed the xiaofei/fix-graceful-shutdown-sample branch from aa5da24 to 9fbbaa8 Compare August 14, 2026 20:26
@XiaoFeiASK

Copy link
Copy Markdown
Author

I have fixed CI😀

Comment thread .github/workflows/github-actions.yml
Comment thread graceful_shutdown/go-server/cmd/main.go
Comment thread go.mod Outdated
@XiaoFeiASK

Copy link
Copy Markdown
Author

新增修改:

  • graceful_shutdown/go-server/cmd/main.go
    问题:为测试构造内部 ShutdownConfig,使用 NewOptions / SetShutdownConfig / server.SetServerShutdown,偏离 sample 应展示的公开 API 用法。
    修复:恢复为直接 dubbo.WithShutdown(...) 传入 graceful shutdown options,并使用 ins.NewServer() 创建 server。
    影响:sample 继续展示推荐的实例级公开配置方式,避免用户参考内部配置注入写法。
  • integrate_test.sh
    问题:自然 graceful shutdown 的 reject 窗口过短,独立 probe 可能在 listener 关闭后才发起,只得到 connection refused,无法证明请求被 provider graceful-shutdown filter 拒绝。
    修复:将 graceful_shutdown 集成测试拆分为两段:第一段验证 in-flight 请求在 shutdown 后完成;第二段启动带 -reject-request=true 的 server,使用独立短连接 probe 稳定验证框架拒绝路径。
    影响:同时满足 in-flight drain 与 framework reject path 的行为验证,避免 CI 依赖短暂时序窗口产生 flake。

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.

[graceful_shutdown] 示例仍使用 graceful_shutdown.Init(...),需改用 WithShutdown API

3 participants