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

[BUG] Concurrent access to Environment.dynamicConfiguration races in common/config

Open lizining1231 opened this issue 3 months ago • 3 comments

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/SetDynamicConfiguration are plain field reads/writes.
  • MockRegistry.Subscribe goroutine blocks on listener.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.

lizining1231 avatar Aug 14 '26 19:08 lizining1231

此PR #3645 的CI复现过该问题,这是grep后的日志 :ci-race.txt 新增:此PR #3668 的CI复现该问题

lizining1231 avatar Aug 14 '26 19:08 lizining1231

请问该issue是否可被采纳,若可以我想跟进该问题

lizining1231 avatar Aug 14 '26 19:08 lizining1231

close via #3669

Alanxtl avatar Aug 19 '26 04:08 Alanxtl