lizining1231 opened a new pull request, #3639:
URL: https://github.com/apache/dubbo-go/pull/3639
### Description
Fixes #3638
Fixes the data race on Server.httpSrv and Server.http3Srv in the triple
protocol server, reported by go test -race ./server/ -run
`TestCfgAPI_Export`.
Server.Start starts the HTTP/2 and HTTP/3 listeners in background goroutines
(startHttp2 / startHttp3 / startHttp2AndHttp3), which write s.httpSrv /
s.http3Srv, while Stop / GracefulStop run on a different goroutine and read
the same fields to call Close / Shutdown — a data race under the Go memory
model.
### Changes
- `httpSrv *http.Server` → `uatomic.Pointer[http.Server]`
- `http3Srv *http3.Server` → `uatomic.Pointer[http3.Server]`
- All write sites go through `Store`
- All read sites go through `Load`; `Stop` / `GracefulStop` load once into a
local snapshot before nil-checking and closing (no TOCTOU)
- Adapt the existing QUIC config tests
(`TestServer_HTTP3PathsUseQUICConfigHelper`)
to `Load()` the atomic pointers before the `assert.Nil` checks, since the
fields are now `uatomic.Pointer` value types that are never nil themselves
### Test
Add 13 tests that start the real HTTP/2, HTTP/3 and dual-protocol servers on
random ports:
Add 13 tests that start the real HTTP/2, HTTP/3 and dual-protocol servers on
random ports:
| Group | Test | Description |
| --- | --- | --- |
| Start + Stop | 1. `TestServer_HTTP2_StartAndStop` | Starts an HTTP/2
server, asserts `httpSrv` is stored and `http3Srv` is empty; `Stop` makes `Run`
return `http.ErrServerClosed` |
| | 2. `TestServer_HTTP2_StartAndStopWithTLS` | Starts HTTP/2 with TLS,
covering the TLS branch of start and stop |
| | 3. `TestServer_HTTP3_StartAndStop` | Starts HTTP/3 (QUIC/UDP), asserts
`http3Srv` is stored and `httpSrv` is empty; `Stop` makes `Run` return
`http.ErrServerClosed` |
| | 4. `TestServer_HTTP2AndHTTP3_StartAndStop` | Starts both protocols,
asserts both fields are non-empty; `Stop` exits cleanly |
| Start + GracefulStop | 1. `TestServer_HTTP2_StartAndGracefulStop` | HTTP/2
`GracefulStop` (`Shutdown` branch), covering the production destroy path |
| | 2. `TestServer_HTTP3_StartAndGracefulStop` | HTTP/3 `GracefulStop`;
`Run` returns `http.ErrServerClosed` |
| | 3. `TestServer_HTTP2AndHTTP3_StartAndGracefulStop` | Dual-protocol
`GracefulStop`; both servers go through `Shutdown` |
| Stop before start | 1. `TestServer_StopBeforeStart` | `Stop` without ever
running: no panic, returns nil |
| | 2. `TestServer_GracefulStopBeforeStart` | `GracefulStop` without ever
running: no panic, returns nil |
| Error paths | 1. `TestServer_Run_HTTP3WithoutTLS` | `Run` with missing TLS
returns an explicit error |
| | 2. `TestServer_Run_HTTP2AndHTTP3WithoutTLS` | `Run` with missing TLS for
the dual protocol returns an explicit error |
| | 3. `TestServer_RunUnsupportedProtocol` | `Run` with an unsupported
protocol returns an explicit error |
| Repeated start/stop | 1. `TestServer_RepeatedStartStop` | 3 protocols × 3
rounds (3-element `protocols` slice × `for range 3`), regression check |
### Validation
- `go test -race -run '^TestServer_HTTP3_StartAndStop$'
./protocol/triple/triple_protocol/`
— this lifecycle test reported a `DATA RACE` on `http3Srv` before the fix,
now passes cleanly under `-race`
- `go test -race ./protocol/triple/triple_protocol/` — passes (the nil
assertions in the QUIC config tests were adapted to the new atomic fields)
### Checklist
- [x] I confirm the target branch is `develop`
- [x] Code has passed local testing
- [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]