lizining1231 opened a new pull request, #3669: URL: https://github.com/apache/dubbo-go/pull/3669
### Description Fixes #3664 (task of #3614) Fixes the data race on the global `Environment.dynamicConfiguration` in `common/config`, reported by the CI `-race` job on the `registry/directory` package. The `Environment` singleton keeps `dynamicConfiguration` as a lock-free field. A test goroutine writes it via `SetDynamicConfiguration`, while subscription goroutines leaked from earlier `normalRegistryDir` tests keep reading it through `GetDynamicConfiguration` (tag `PriorityRouter.Notify`) — a data race under the Go memory model. The registry subscription goroutine blocks on `listener.Next()` and never exits, so it survives across tests and races with the writer of the next test. ### Changes - Add a `dynamicMu sync.RWMutex` field to `Environment` - `SetDynamicConfiguration` takes the write lock before storing - `GetDynamicConfiguration` takes the read lock before loading - The exported API and nil semantics are unchanged, so existing callers and tests are unaffected ### Test Add `TestDynamicConfigurationRace` in `environment_race_test.go`: | Test | Description | | --- | --- | | `TestDynamicConfigurationRace` | Drives 100k concurrent reads and writes on the global `Environment.dynamicConfiguration`: a reader goroutine mimics a lingering registry subscription goroutine calling `GetDynamicConfiguration`, while the test goroutine keeps calling `SetDynamicConfiguration`. Fails on the previous lock-free field under `-race` and passes with the `RWMutex` guard | ### Validation - `go test -race -run TestDynamicConfigurationRace ./common/config/ -count=1` reports a `DATA RACE` `dynamicConfiguration` before the fix, passes after it - `-race` runs pass with no `DATA RACE` reported. ### Checklist - [x] I confirm the target branch is `develop` - [x] I have run `make fmt` to format my code - [x] I have run `make test` to run local tests - [x] I have added tests that prove my fix is effective or that my feature works -- 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]
