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())