lizining1231 opened a new issue, #3638:
URL: https://github.com/apache/dubbo-go/issues/3638
### Summary
Run go test -race ./server/ -run TestCfgAPI_Export reports a data race in
the triple server involving the Server. httpSrv and Server.http3Srv fields:
the startup path writes to these two fields in a background goroutine,
while the shutdown path reads them in another goroutine, with no
synchronization mechanism between them. This issue is part of #3614.
### Affected Locations
| Package | Test | Test Location
| Related Source Locations
|
| ---------- | --------------------- |
---------------------------------------------------------------------------- |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 7. server | TestCfgAPI_Export | <
https://github.com/apache/dubbo-go/blob/master/server/inst_test.go#L85-L90 > |
Write <
https://github.com/apache/dubbo-go/blob/master/protocol/triple/triple_protocol/server.go#L200
> ( startHttp2 assigns s.httpSrv ) races with read <
https://github.com/apache/dubbo-go/blob/master/protocol/triple/triple_protocol/server.go#L326
> ( GracefulStop reads s.httpSrv ); s.http3Srv is analogous ( startHttp3
writes L224 / GracefulStop reads L328 ) |
### Reproduction
Before the fix, the write/read race on httpSrv / http3Srv reproduces
reliably
```bash
go test -race ./server/ -run `TestCfgAPI_Export`
```
### Root Cause
Server.Start launches startHttp2 / startHttp3 / startHttp2AndHttp3
through an errgroup , writing s.httpSrv / s.http3Srv inside goroutines;
Stop / GracefulStop run on another goroutine (e.g.
TripleProtocol.Destroy
on unexport) and read the same fields to call Close / Shutdown .
There is no happens-before edge between the write on the start path and the
read on the stop path, which is a data race under the Go memory model.
### Proposed Fix
- Change the fields to `uatomic.Pointer` :
- httpSrv *http.Server → uatomic.Pointer[http.Server]
- http3Srv *http3.Server → uatomic.Pointer[http3.Server]
- 4 write sites go through Store
- 10 read sites go through Load
--
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]