Alanxtl commented on code in PR #3645:
URL: https://github.com/apache/dubbo-go/pull/3645#discussion_r3763172874
##########
protocol/triple/triple_protocol/server.go:
##########
@@ -264,6 +270,28 @@ func (s *Server) startHttp2AndHttp3(tlsConf *tls.Config)
error {
return err
}
+ if len(tlsConf.Certificates) == 0 &&
+ tlsConf.GetCertificate == nil &&
+ tlsConf.GetConfigForClient == nil {
+ return fmt.Errorf("TRIPLE HTTP/2 and HTTP/3 Server must have a
TLS certificate configured, but none of
Certificates/GetCertificate/GetConfigForClient is set")
+ }
+
+ // Pre-bind the TCP (HTTP/2) listener before serving any request:
+ // fail fast with the bind error when the port is occupied.
+ tcpLn, err := netListen("tcp", s.addr)
+ if err != nil {
+ return fmt.Errorf("HTTP/2 server bind error: %w", err)
+ }
+ defer tcpLn.Close()
+
Review Comment:
`Stop` 可能在启动阶段失效,导致服务继续启动并泄漏
`tcpLn` 和 `udpConn` 都完成预绑定后,代码才调用 `http3Srv.Store` / `httpSrv.Store`。如果另一个
goroutine 在这段期间调用 `Stop()`,两个指针都是 `nil`,`Stop()` 会立即返回成功;随后启动流程继续执行并进入两个
`Serve`,这次 `Stop` 不会再有机会关闭它们。
这会导致调用方认为服务已经停止,但实际服务仍在监听,尤其在启动超时、服务关闭或进程生命周期管理场景下可能造成端口和 goroutine
泄漏。新增的并发测试通过第二次 `Stop()` 补救了这个窗口,因此没有覆盖真实问题。
建议增加启动/停止状态同步:让 `Stop` 能取消正在进行的启动流程,或在启动阶段保存并管理 pre-bound
listener,使启动检测到已停止后立即关闭 listener 并返回。
--
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]