dubbo-go
dubbo-go copied to clipboard
[BUG] Concurrent access to Environment.dynamicConfiguration races in common/config
Summary
go test -race ./registry/directory/ intermittently reports a data race: a subscription goroutine left over from an earlier test reads the global common/config.Environment.dynamicConfiguration field while the current test goroutine writes it — no synchronization, no happens-before edge.
Affected Locations
| Package | Test | Test Location | Related Source |
|---|---|---|---|
| registry/directory | TestNewRegistryDirectoryConsumerListenerUsesResolvedApplicationName |
directory_test.go#L191-L198 (write at L195) | Write: environment.go#L100-L104; Read: environment.go#L106-L111 via router.go#L109 → chain.go#L115 → directory.go#L413 → mock_registry.go#L116 |
Reproduction
# before the fix: deterministic (minimal stress test)
go test -race -run TestDynamicConfigurationRace ./common/config/
# CI: flaky under the full suite
go test -race ./registry/directory/
Root Cause
- Global lock-free field:
Get/SetDynamicConfigurationare plain field reads/writes. MockRegistry.Subscribegoroutine blocks onlistener.Next()forever, surviving across tests (reader goroutine ID < writer goroutine ID proves cross-test).- Lingering reader consumes backlogged events while the current test writes → race.
Proposed Fix
- Add
sync.RWMutex(write lock in Set, read lock in Get). - Regression test
TestDynamicConfigurationRace: 100k reads vs 100k writes, fails before fix, passes after.
此PR #3645 的CI复现过该问题,这是grep后的日志 :ci-race.txt 新增:此PR #3668 的CI复现该问题
请问该issue是否可被采纳,若可以我想跟进该问题
close via #3669