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

   Related to #3614
   
   ## Background
   
   `TestGrpcHealthWatchEmitsClosingEvent` is one of the data races tracked in 
#3614.
   
   The test starts the gRPC health-watch loop in a background goroutine. When a 
closing event is emitted, `testClosingEventHandler.HandleClosingEvent` appends 
the event to the shared `events` slice, while the test goroutine reads the same 
slice concurrently.
   
   Running the test with the race detector reports concurrent reads and writes 
to `handler.events`.
   
   ## Root cause
   
   `testClosingEventHandler.events` was accessed from multiple goroutines 
without synchronization.
   
   The health-watch goroutine writes to the slice in `HandleClosingEvent`, 
while the test reads:
   
   - `len(handler.events)`
   - `handler.events[0]`
   
   There was no synchronization establishing a happens-before relationship 
between these accesses.
   
   ## Changes
   
   - Protect `testClosingEventHandler.events` with `sync.RWMutex`.
   - Add `eventsSnapshot` to provide synchronized reads without exposing the 
internal slice.
   - Update affected tests to use the snapshot instead of directly accessing 
`events`.
   - Remove `TestGrpcHealthWatchEmitsClosingEvent` from `RACE_SKIP_TESTS`.
   
   ## Testing
   
   ```text
   go test -race ./protocol/grpc -run "^TestGrpcHealthWatchEmitsClosingEvent$" 
-count=20
   go test -race ./protocol/grpc -count=1
   ```
   
   ### 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
   - [ ] 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