lizining1231 commented on PR #3671:
URL: https://github.com/apache/dubbo-go/pull/3671#issuecomment-5312656076
> 如果是因为错误而关闭了server是不是同样也走这个分支
是的
```go
if err != nil && err != http.ErrServerClosed {
return err // genuine errors still propagate
}
return nil // only the normal-closure signal is swallowed
```
可以构造一个因为错误关闭server的测试:
```go
// TestZZNonNormalShutdownLogs verifies that a genuine serve error (port
// conflict) surfaces as a "server serve failed" log line through the real
// startTransport -> Run call chain. Temporary probe, deleted after the run.
func TestZZNonNormalShutdownLogs(t *testing.T) {
// Occupy a TCP port so the upcoming ListenAndServe fails to bind.
l, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
defer l.Close()
srv := NewServer(&global.TripleConfig{})
srv.triServer = tri.NewServer(l.Addr().String(), &global.TripleConfig{})
srv.startTransport(constant.CallHTTP2, nil)
// Give the goroutine time to run Run() and log the failure.
time.Sleep(500 * time.Millisecond)
}
```
运行的话就是正常看到报错日志:
```bash
lizining@Y:~/projects/dubbo-go$ go test -v -run TestZZNonNormalShutdownLogs
./protocol/triple/
=== RUN TestZZNonNormalShutdownLogs
2026-08-17T14:17:09.038+0800 ERROR triple/server.go:238
[Triple][Server] server serve failed, err=listen tcp 127.0.0.1:37831: bind:
address already in use
dubbo.apache.org/dubbo-go/v3/protocol/triple.(*Server).startTransport.func1
/home/lizining/projects/dubbo-go/protocol/triple/server.go:238
--- PASS: TestZZNonNormalShutdownLogs (0.50s)
PASS
ok dubbo.apache.org/dubbo-go/v3/protocol/triple (cached)
```
--
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]