From 627912a7883c9af699e6feaa1a61ae3d39d525a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 19 Jun 2026 20:57:18 +0800 Subject: [PATCH] Fix naive inbound QUIC ALPN race condition --- protocol/naive/inbound.go | 18 +++++++++--------- protocol/naive/quic/inbound_init.go | 4 ++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/protocol/naive/inbound.go b/protocol/naive/inbound.go index 41f41798..c9d6a1ae 100644 --- a/protocol/naive/inbound.go +++ b/protocol/naive/inbound.go @@ -107,16 +107,16 @@ func (n *Inbound) Start(stage adapter.StartStage) error { return n.ctx }, } - go func() { - listener := net.Listener(tcpListener) - if n.tlsConfig != nil { - if len(n.tlsConfig.NextProtos()) == 0 { - n.tlsConfig.SetNextProtos([]string{http2.NextProtoTLS, "http/1.1"}) - } else if !common.Contains(n.tlsConfig.NextProtos(), http2.NextProtoTLS) { - n.tlsConfig.SetNextProtos(append([]string{http2.NextProtoTLS}, n.tlsConfig.NextProtos()...)) - } - listener = aTLS.NewListener(tcpListener, n.tlsConfig) + listener := net.Listener(tcpListener) + if n.tlsConfig != nil { + if len(n.tlsConfig.NextProtos()) == 0 { + n.tlsConfig.SetNextProtos([]string{http2.NextProtoTLS, "http/1.1"}) + } else if !common.Contains(n.tlsConfig.NextProtos(), http2.NextProtoTLS) { + n.tlsConfig.SetNextProtos(append([]string{http2.NextProtoTLS}, n.tlsConfig.NextProtos()...)) } + listener = aTLS.NewListener(tcpListener, n.tlsConfig) + } + go func() { sErr := n.httpServer.Serve(listener) if sErr != nil && !errors.Is(sErr, http.ErrServerClosed) { n.logger.Error("http server serve error: ", sErr) diff --git a/protocol/naive/quic/inbound_init.go b/protocol/naive/quic/inbound_init.go index 1f868267..b391a263 100644 --- a/protocol/naive/quic/inbound_init.go +++ b/protocol/naive/quic/inbound_init.go @@ -19,6 +19,7 @@ import ( "github.com/sagernet/sing-quic/congestion_bbr2" congestion_meta1 "github.com/sagernet/sing-quic/congestion_meta1" congestion_meta2 "github.com/sagernet/sing-quic/congestion_meta2" + "github.com/sagernet/sing/common" E "github.com/sagernet/sing/common/exceptions" "github.com/sagernet/sing/common/logger" "github.com/sagernet/sing/common/ntp" @@ -30,6 +31,9 @@ func init() { if err != nil { return nil, err } + if !common.Contains(tlsConfig.NextProtos(), http3.NextProtoH3) { + tlsConfig.SetNextProtos(append(append([]string{}, tlsConfig.NextProtos()...), http3.NextProtoH3)) + } udpConn, err := listener.ListenUDP() if err != nil {