[Bug] single-protocol server misreports normal Stop as serve failure
Summary
In protocol/triple, a single-protocol (HTTP/2 or HTTP/3) server leaks http.ErrServerClosed from Server.Run after a normal Stop. The outer startTransport goroutine treats any non-nil error as a serve failure and logs [Triple][Server] server serve failed, err=http: Server closed every time the server is shut down normally — spurious error logs and monitoring noise. The dual-protocol path (startHttp2AndHttp3) already filters http.ErrServerClosed inside its errgroup, so the single-protocol and dual-protocol paths behave inconsistently.
Affected Locations
| Package | Test | Test Location | Related Source |
|---|---|---|---|
| protocol/triple/triple_protocol | TestServer_HTTP2_StartAndStop / TestServer_HTTP3_StartAndStop / TestServer_HTTP2_StartAndGracefulStop / TestServer_HTTP3_StartAndGracefulStop / TestServer_RepeatedStartStop |
https://github.com/apache/dubbo-go/blob/master/protocol/triple/triple_protocol/server_lifecycle_test.go#L170-L203 | Single-protocol: https://github.com/apache/dubbo-go/blob/master/protocol/triple/triple_protocol/server.go#L201-L220 (startHttp2 returns err directly) and #L222-L250 (startHttp3); Logging: https://github.com/apache/dubbo-go/blob/master/protocol/triple/server.go#L230-L241 (startTransport goroutine logs serve failed on any non-nil error) |
Reproduction
# single-protocol HTTP/2 server, then Stop:
go test -run 'TestServer_HTTP2_StartAndStop' ./protocol/triple/triple_protocol/
# observed: Run returns http.ErrServerClosed after a normal Stop (test asserts it today),
# which makes the outer goroutine log "server serve failed, err=http: Server closed"
The existing tests currently assert the leak (require.ErrorIs(..., http.ErrServerClosed)), i.e. they pin the buggy behavior as expected instead of asserting a clean shutdown. The dual-protocol sibling test asserts require.NoError(...) — the inconsistency is baked into the test suite.
Root Cause
startHttp2(server.go#L201-L220) andstartHttp3(server.go#L222-L250) return theListenAndServeerror verbatim, without filteringhttp.ErrServerClosed— the normal-shutdown signal from net/http.startHttp2AndHttp3(server.go#L292-L313) already filterserr != http.ErrServerClosedinside the errgroup, so dual-protocolRunreturnsnilafter a normal stop.startTransport(protocol/triple/server.go#L230-L241) logslogger.Errorf("... server serve failed, err=%v", runErr)for any non-nilRunerror.- Net effect: single-protocol deployments log a spurious error on every normal shutdown, while dual-protocol deployments do not — inconsistent behavior across the three
Runswitch branches.
Proposed Fix
- Filter
http.ErrServerClosedinstartHttp2andstartHttp3before returning, aligning them withstartHttp2AndHttp3. Note: onlyhttp.ErrServerClosedis swallowed; genuine errors (e.g.EADDRINUSEon bind) still propagate. - Update the 6 assertions in
server_lifecycle_test.go(L178/L189/L203/L233/L249/L340) fromrequire.ErrorIs(..., http.ErrServerClosed)torequire.NoError(...). Theif/elseinTestServer_RepeatedStartStopthen becomes uniform and can be simplified. - Verification: the updated tests fail on the pre-fix code (they assert
nilwhileRunreturnsErrServerClosed) and pass after the one-line fix; full./protocol/triple/...suite green.
请求分配,谢谢
这个改动会修改我在 #3639 中写的部分测试断言,原先断言按照原先实际行为编写,现作修改
close via #3671