lizining1231 opened a new issue, #3664: URL: https://github.com/apache/dubbo-go/issues/3664
### 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](https://github.com/apache/dubbo-go/blob/master/registry/directory/directory_test.go#L191-L198) (write at L195) | Write: [environment.go#L100-L104](https://github.com/apache/dubbo-go/blob/master/common/config/environment.go#L100-L104); Read: [environment.go#L106-L111](https://github.com/apache/dubbo-go/blob/master/common/config/environment.go#L106-L111) via [router.go#L109](https://github.com/apache/dubbo-go/blob/master/cluster/router/tag/router.go#L109) → [chain.go#L115](https://github.com/apache/dubbo-go/blob/master/cluster/router/chain/chain.go#L115) → [directory.go#L413](https://github.com/apache/dubbo-go/blob/master/registry/directory/directory.go#L413) → [mock_registry.go#L116](https://github.com/apache/dubbo-go/blob/master/registry/mock_registry.go#L116) | ### Reproduction ```bash # 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
