From 6ce4bf7726d3458d267ce2e7e25e74fe67a544c3 Mon Sep 17 00:00:00 2001 From: wangjian Date: Wed, 5 Apr 2023 11:17:38 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=A6=82=E6=9E=9C=E6=8A=A5=E9=94=99?= =?UTF-8?q?=EF=BC=8C=E5=B0=B1=E4=BC=9A=E6=8B=92=E7=BB=9D=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server.go b/server.go index 640c308..c06925a 100644 --- a/server.go +++ b/server.go @@ -127,21 +127,22 @@ func (s *Server) createNewClientConnection(ctx context.Context, listener Listene go func(ctx context.Context, qConn quic.Connection) { for { - err := s.handle(ctx, qConn, connect, connId) + err := s.handle(ctx, qConn, connId) if err != nil { - continue + break } } }(sctx, connect) return nil } -func (s *Server) handle(ctx context.Context, qConn quic.Connection, conn quic.Connection, connId string) error { +func (s *Server) handle(ctx context.Context, qConn quic.Connection, connId string) error { log.Infof("%s2/ waiting for new stream", ServerLogPrefix) stream, err := qConn.AcceptStream(ctx) if err != nil { name := "--" - if conn := s.connector.Get(connId); conn != nil { + conn := s.connector.Get(connId) + if conn != nil { _ = conn.Close() // connector s.connector.Remove(connId) @@ -150,6 +151,9 @@ func (s *Server) handle(ctx context.Context, qConn quic.Connection, conn quic.Co _ = route.Remove(connId) } name = conn.Name() + } else { + _ = s.Close() + } log.Printf("%s [%s](%s) close the connection: %v", ServerLogPrefix, name, connId, err) return err @@ -161,7 +165,7 @@ func (s *Server) handle(ctx context.Context, qConn quic.Connection, conn quic.Co log.Infof("%s3/ [stream:%d] created, connId=%s", ServerLogPrefix, stream.StreamID(), connId) // process frames on stream // c := newContext(connId, stream) - c := newContext(conn, stream) + c := newContext(qConn, stream) defer c.Clean() s.handleConnection(c) log.Infof("%s4/ [stream:%d] handleConnection DONE", ServerLogPrefix, stream.StreamID())