fix: h2 close panic

This commit is contained in:
wwqgtxx 2023-04-17 23:42:15 +08:00
parent f100ce6a04
commit 47df97322d

View File

@ -1,6 +1,7 @@
package vmess package vmess
import ( import (
"context"
"io" "io"
"net" "net"
"net/http" "net/http"
@ -84,10 +85,16 @@ func (hc *h2Conn) Write(b []byte) (int, error) {
} }
func (hc *h2Conn) Close() error { func (hc *h2Conn) Close() error {
if err := hc.pwriter.Close(); err != nil { if hc.pwriter != nil {
return err 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 err
} }
return hc.Conn.Close() return hc.Conn.Close()