dubbo-go icon indicating copy to clipboard operation
dubbo-go copied to clipboard

[Bug] The Triple server has a data race on its httpSrv and http3Srv fields

Open lizining1231 opened this issue 3 months ago • 2 comments

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

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

lizining1231 avatar Aug 10 '26 16:08 lizining1231

请分配给我,谢谢

lizining1231 avatar Aug 10 '26 17:08 lizining1231

close via #3639

Alanxtl avatar Aug 11 '26 12:08 Alanxtl