Repository navigation
bugfix: restore naming server client lifecycle after close - #1199
yangjj-iso wants to merge 9 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1199 +/- ##
==========================================
+ Coverage 65.31% 65.33% +0.01%
==========================================
Files 312 312
Lines 23890 23899 +9
==========================================
+ Hits 15604 15614 +10
+ Misses 6873 6871 -2
- Partials 1413 1414 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Plz resolve the conflicts. |
Preserve all upstream release notes and both entries for apache#1198. Validation: targeted NamingServer lifecycle regressions pass with the race detector (three runs) on Go 1.20.14. Two full-package Watch tests also fail unchanged on master because this environment denies local interface discovery.
XiaoFeiASK
left a comment
There was a problem hiding this comment.
Thanks for the fix, @yangjj-iso. The direction is right: each NamingServer registry service now owns its client, and GetInstance no longer returns a closed cached client. All CI checks pass on 4beb449; I also ran go test ./pkg/discovery -count=1 and the targeted lifecycle tests under -race locally.
I do not see a merge-blocking correctness issue in this revision. Two non-blocking points are below.
P2 (non-blocking): repeated InitRegistry leaves the previous client running
newNamingServerRegistryService(...) now creates a fresh client on every call (pkg/discovery/naming_server.go:248-250). That client immediately starts a ticker and health-check goroutine (pkg/discovery/naming_server.go:273-284).
InitRegistryWithError still replaces registryServiceInstance without closing the previous instance (pkg/discovery/init.go:44-51). If InitRegistry is called again without closing the old registry, the old client is no longer reachable from GetRegistry(), but its ticker, health-check goroutine, and any watchLoop created by Lookup/Subscribe continue running. Repeated reinitialization therefore accumulates background work and may keep delivering events from a stale registry.
This is not blocking today because the normal client path is guarded by sync.Once (pkg/client/client.go:133-136). If repeated initialization is not supported, please state that contract; otherwise close the previous instance before replacement or reject a second initialization.
P3: the regression test only proves the client is not closed
TestGetInstanceRecreatesClosedClient checks that second != first and that second.closeChan is open (pkg/discovery/naming_server_test.go:59-73). It would still pass if the replacement client failed to start health checks or could not watch. A mock-server assertion that the recreated client performs a health check or watch would make the lifecycle regression explicit.
The change itself looks correct and I do not see anything else blocking.
Resolve both changelog conflicts while preserving upstream entries. Document startup-only registry initialization and explicit prior-service cleanup. Verify the recreated client resumes background health checks against a local server.
|
Addressed the follow-up in
The lifecycle race tests pass for 30 repetitions; the discovery suite passes with the two environment-dependent watch tests explicitly excluded; vet and formatting pass. Both excluded failures reproduce on unchanged Hosted validation currently has 16 successful checks, including the unit-test workflow. The integration workflow reports |
The enterprise action policy blocks docker/setup-buildx-action@v3 before any integration job starts. Both sample Compose stacks use prebuilt images, so verify the runner's existing Docker client and daemon instead of creating an unused Buildx builder. Keep all integration steps enabled. Validation: actionlint 1.7.7 and git diff --check pass.
|
Follow-up in The integration scripts only run prebuilt images and do not need a Buildx builder. I replaced that unused setup action with
|
| longPollClient: &http.Client{Timeout: 30 * time.Second}, | ||
| namingServerMu.Lock() | ||
| defer namingServerMu.Unlock() | ||
| if namingServerInstance != nil { |
There was a problem hiding this comment.
[P2] GetInstance 的“关闭后重建”分支在本仓库已无生产调用方,单例生命周期机制变为测试专属代码
本 PR 把 newNamingServerRegistryService 改为直接调用 newNamingServerClient(pkg/discovery/naming_server.go:248),GetInstance 从此在本仓库内只被 naming_server_test.go 调用(grep -rn "GetInstance\b" --include=*.go . 仅命中定义与测试)。也就是说,changes/dev.md 声明的“recreate a closed NamingServer client”实际是由“每个 registry service 独立持有 client”实现的;namingServerInstance、namingServerMu、resetInstance(仍保留 Close() + clearNamingAddrCache() 的清理逻辑)以及这里新增的关闭检测分支,只剩测试在使用。
触发条件与影响:后续若有代码按 GetInstance 的语义复用它,拿到的生命周期模型与仓库实际的注册路径不同;两套模型并存时,resetInstance 清理的是单例,而 registry service 关闭的是自持 client,改动其中一处不会同步到另一处,resetInstance 的清缓存行为也不再被任何生产路径验证。
建议二选一:① 删除 GetInstance / resetInstance / namingServerInstance / namingServerMu,测试改用 newNamingServerClient 并显式 Close;② 让 newNamingServerRegistryService 仍经由 GetInstance,把重建语义收敛到单一入口。若 GetInstance 因对外 API 需要保留,请在注释中写明它不参与 registry 初始化路径,并在变更日志里区分“单例重建”与“每服务独立 client”两件事。
|
lgtm |
Keep the NamingServer lifecycle entry and the upstream IPv6 coordinator entry in the development changelog. Preserve the upstream file mode. Targeted discovery race tests passed for 15 repetitions. The affected packages passed with the two discovery watch tests excluded after confirming both also fail on unchanged master in this environment. Go vet and diff checks passed.
Signed-off-by: redyyang <redyyang@tencent.com>
The sample module declares Go 1.25. Integration now uses Go 1.25 while the library minimum-version jobs keep Go 1.20. Reproduced the integration module edits and built the sample integration packages with Go 1.25.5. Signed-off-by: redyyang <redyyang@tencent.com>
What this PR does:
GetInstanceclient after it has been closed, while preserving reuse of an active client.Which issue(s) this PR fixes:
Fixes #1198
Special notes for your reviewer:
Validation of
3a40d90after merging currentmaster(82570d9), with Go 1.25.5 on Linux:go test -race ./pkg/discovery -run 'TestGetInstanceRecreatesClosedClient|TestNamingServerRegistryServicesOwnClients|TestInitRegistry_WithNamingServerConfig|TestInitRegistryWithErrorSupportedProviders' -count=30.go test ./pkg/discovery -skip '^(TestWatch|TestSubscribeStartsWatchLoopPerVGroup)$' -count=1passed.go vet ./pkg/discovery, gofmt, andgit diff --checkpassed.TestWatchfails because this environment denies the netlink operation used to determine the local IP;TestSubscribeStartsWatchLoopPerVGroupalso times out. Both failures reproduce on unchangedmasterat82570d9. Full-suite success is not claimed for this environment.beb4891594fa8cb26eae8ad9ae2c28b9a48b02bf).Hosted validation of
293c4e3: all 17 checks pass, including full unit tests, integration tests, lint, build, Go Vet, CodeQL, licenses, and the three Go-version transaction jobs. The previous integration startup failure came from the unuseddocker/setup-buildx-action@v3step being disallowed by the repository's action policy. This follow-up uses the hosted runner's existing Docker installation and verifies it withdocker versionanddocker info; all integration steps remain in place.actionlintandgit diff --checkpass for the workflow change.Does this PR introduce a user-facing change?:
Yes. NamingServer registry services can be recreated after closure, and closing one no longer stops another service's client.