dubbo-go icon indicating copy to clipboard operation
dubbo-go copied to clipboard

[Bug] go test -race exposes 10 data races (8 packages)

Open lizining1231 opened this issue 3 months ago • 7 comments

Summary

Running go test -race ./... fails 10 tests across 8 packages due to Data Race.

This issue categorizes the failures by reproducibility and lists the failing test locations, related source locations, and initial analysis, all for evaluating fixes or marking them as known issues.

Affected Locations

1. Stable data races (reproducible both in a full-suite run and in per-package runs)

Package Test Test Location Related Source Location
1. cluster/cluster/failback TestFailbackRetryFailed cluster_test.go L136-L180 Read cluster_invoker.go L109 (process reads lastT) vs Write cluster_invoker.go L198-L212 (checkRetry writes lastT/nextBackoff)
2. cluster/cluster/failback TestFailbackOutOfLimit cluster_test.go L231-L263 Write cluster_invoker.go L95 (process creates ticker) vs Read cluster_invoker.go L173 (Destroy calls ticker.Stop)
3. cluster/router/chain TestRouteCacheGenerationRace chain_test.go L423-L474 Write chain_test.go L386 (SetCache writes r.cache) vs Read chain_test.go L401 (Route reads r.cache)
4. config_center/apollo TestListener impl_test.go L257-L288 Map iteration listener.go L56 vs Write listener.go L68/L74; also the test's own global variable impl_test.go L98 (reads mockConfigRes) vs L261 (writes mockConfigRes), and L300-L302 (Process writes event/count) vs L273-L274 (the test reads)
5. protocol/dubbo TestDubboProtocol_Refer dubbo_protocol_test.go L129-L152 Third-party dubbo-getty v1.4.10: session.go L857 (s.ReadTimeout()) vs connection.go L277-L278 (SetReadDeadline/Store)
6. protocol/grpc TestGrpcHealthWatchEmitsClosingEvent active_notify_test.go L88-L139 Write active_notify_test.go L51 (callback goroutine append events) vs Read active_notify_test.go L133 (test goroutine len(events))
registry/servicediscovery (unnumbered) TestServiceDiscoveryRegistryUnRegister_Concurrent service_discovery_registry_test.go L1307-L1371 service_discovery_registry_test.go L1368 lock-free append(sdReg.instances, ...). Note: the test intentionally omits locking to simulate a real concurrent scenario, and the race is the expected outcome of the test.
7. server TestCfgAPI_Export inst_test.go L85-L90 Write server.go L200 (startHttp2 assigns s.httpSrv) vs Read server.go L326 (GracefulStop reads s.httpSrv)

2. Non-deterministic data races (unstable reproduction: intermittent on a single run, always reproducible with -count=N)

Package Test Test Location Related Source Location
8. server TestCfgAPI_Call https://github.com/apache/dubbo-go/blob/master/server/inst_test.go#L94-L100 Same as TestCfgAPI_Export: https://github.com/apache/dubbo-go/blob/master/protocol/triple/triple_protocol/server.go#L200 vs https://github.com/apache/dubbo-go/blob/master/protocol/triple/triple_protocol/server.go#L326 (passes on a single -run, race reproduces with -count=3)
9. remoting/getty TestTCPPackageHandle https://github.com/apache/dubbo-go/blob/master/remoting/getty/readwriter_test.go#L45-L50 Read https://github.com/apache/dubbo-go/blob/master/remoting/getty/readwriter.go#L128 (Write reads global srvConf) vs Write https://github.com/apache/dubbo-go/blob/master/remoting/getty/getty_server.go#L116-L117 (SetServerConfig writes srvConf). Always reported in full-suite runs, intermittent when run alone
10. common/config TestNewRegistryDirectoryConsumerListenerUsesResolvedApplicationName https://github.com/apache/dubbo-go/blob/master/registry/directory/directory_test.go#L191-L198 Write https://github.com/apache/dubbo-go/blob/master/common/config/environment.go#L100 (SetDynamicConfiguration) vs Read https://github.com/apache/dubbo-go/blob/master/common/config/environment.go#L105 (GetDynamicConfiguration). Cross-test race: the reader goroutine is a `MockRegistry.

Suggested Fixes

Detailed solutions for each issue will be submitted in separate issues; this issue only lists the scope of the fixes.

Verification

These tests are skipped via -skip in CI. To reproduce locally, remove the corresponding tests from -skip and run:

GOTOOLCHAIN=go1.25.0 go test -race -count=1 ./...

Category 1 (stable) appears on a single run; for Category 2 (unstable), use -count=N to increase the hit rate.

lizining1231 avatar Aug 07 '26 18:08 lizining1231

这里是两份复现日志,结构均为:上半部分为FAIL 测试列表,下半部分为完整的 WARNING: DATA RACE 块(含读写冲突的 goroutine 堆栈和文件行号) race_grep.log,

race_cfgapi_call.log

FAIL测试列表:

Image Image

lizining1231 avatar Aug 07 '26 19:08 lizining1231

请问这个issue是否可被采纳?如果可以我想跟进 7

lizining1231 avatar Aug 07 '26 19:08 lizining1231

请问这个issue是否可被采纳?如果可以我想跟进 7

好 继续跟进吧

Alanxtl avatar Aug 08 '26 00:08 Alanxtl

issue7 对应Issue #3638 PR #3639 ,接下来我会更进4

lizining1231 avatar Aug 10 '26 19:08 lizining1231

issue10对应 issue #3664, PR #3669

lizining1231 avatar Aug 16 '26 08:08 lizining1231

请问我可以接手其中的第 6 个问题 TestGrpcHealthWatchEmitsClosingEvent 的 data race 吗?我已经在本地复现了这个问题。

Qianlin1455 avatar Oct 08 '26 10:10 Qianlin1455

请问我可以接手其中的第 6 个问题 TestGrpcHealthWatchEmitsClosingEvent 的 data race 吗?我已经在本地复现了这个问题。

当然,非常感谢!

lizining1231 avatar Oct 08 '26 10:10 lizining1231