From 47df97322db5e4dc28a4c39441c27b401bf53ca6 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Mon, 17 Apr 2023 23:42:15 +0800 Subject: [PATCH] fix: h2 close panic --- transport/vmess/h2.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/transport/vmess/h2.go b/transport/vmess/h2.go index 6901f61e..f91c2766 100644 --- a/transport/vmess/h2.go +++ b/transport/vmess/h2.go @@ -1,6 +1,7 @@ package vmess import ( + "context" "io" "net" "net/http" @@ -84,10 +85,16 @@ func (hc *h2Conn) Write(b []byte) (int, error) { } func (hc *h2Conn) Close() error { - if err := hc.pwriter.Close(); err != nil { - return err + if hc.pwriter != nil { + if err := hc.pwriter.Close(); err != nil { + return err + } } - if err := hc.ClientConn.Shutdown(hc.res.Request.Context()); err != nil { + ctx := context.Background() + if hc.res != nil { + ctx = hc.res.Request.Context() + } + if err := hc.ClientConn.Shutdown(ctx); err != nil { return err } return hc.Conn.Close()