lizining1231 commented on code in PR #3645:
URL: https://github.com/apache/dubbo-go/pull/3645#discussion_r3767173550


##########
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 失效导致服务仍启动问题已修复
   
   好的,谢谢!我已添加 ”在启动阶段保存并管理 pre-bound listener,使启动检测到已停止后立即关闭 listener 
并返回“的改动,具体改动如下:
   
   - Server 新增字段 `stopCount uatomic.Uint32`,这里考虑到 bool 类型服务 Stop 过就无法再次 
Start,为支持反复启停,此处选用 uint32
   - 启动开头拍照:`epoch := s.stopCount.Load()`
   - `Stop()` / `GracefulStop()` 入口先 `s.stopCount.Add(1)`,再继续走原有关闭逻辑
   - 启动在 `Store` 之后、`Serve` 之前检查:
   
   ```go
   if s.stopCount.Load() != epoch {
       return nil
   }
   ```
   
   检测到停止即中止启动,由 defer 关闭预绑定 socket 后返回
   
   - 添加测试 `TestServer_HTTP2AndHTTP3_StopDuringStartup`:钩子在 TCP 预绑定后注入 Stop(两指针仍 
nil),断言 Run 中止返回 + TCP/UDP 端口可重绑
   - `TestServer_HTTP2AndHTTP3_StopDuringStartupDoesNotServe`:在预绑定后注入 
Stop,断言启动中止且 Run 返回后,主动连接该地址必须失败(证明确实无服务在监听),且 TCP/UDP 端口均可重新绑定



-- 
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]

Reply via email to