mochengqian opened a new pull request, #3307:
URL: https://github.com/apache/dubbo-go/pull/3307

   ### Description
   Fixes #3304.
   
   This PR removes data races in the Triple protocol initialization path and 
the shared `BaseProtocol` invoker tracking path.
   
   ## Why
   
   When Triple clients/services are created concurrently, `go test -race` can 
report races in two places:
   
   1. `triple.GetProtocol()` lazily initializes the global Triple protocol 
singleton without synchronization.
   2. `BaseProtocol.SetInvokers()` appends to the shared invoker slice while 
other goroutines may read or destroy the same slice.
   
   The second issue is not only a race detector warning. Concurrent appends can 
also lose invoker references, which can affect lifecycle cleanup.
   
   ## How
   
   - Protect Triple protocol singleton initialization with `sync.Once`.
   - Add an internal `RWMutex` for `BaseProtocol` invoker list access.
   - Make `Invokers()` return a snapshot instead of exposing the internal slice.
   - Make `Destroy()` snapshot and clear invokers under lock, then destroy 
invokers outside the lock.
   - Add race regression tests for concurrent Triple protocol initialization 
and concurrent BaseProtocol invoker access.
   - Fix the Triple health-watch test helper to avoid unsynchronized test-only 
slice access, so package-level race verification stays clean.
   
   ## Compatibility
   
   This PR does not change Triple RPC semantics, method lookup behavior, 
retry/timeout/error propagation, serialization, or public protocol contracts.
   
   The only intentional behavior tightening is that `Invokers()` now returns a 
snapshot instead of the internal slice, preventing external callers from 
mutating shared protocol state.
   
   ## Tests
   go test -race ./protocol/base -count=1
   go test -race ./protocol/triple -count=1
   go test ./protocol/base ./protocol/triple -count=1
   go test ./protocol/dubbo ./protocol/dubbo3 ./protocol/grpc 
./protocol/jsonrpc ./protocol/rest -count=1
   go test ./server -run TestTripleCaseInsensitiveRoute -count=1
   go vet ./protocol/base ./protocol/triple
   git diff --check
   
   
   ### Checklist
   - [ ] I confirm the target branch is `develop`
   - [ ] Code has passed local testing
   - [ ] 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]

Reply via email to