From b283869c7232c9020991102e56485cd00b31fdf5 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Tue, 29 Dec 2020 11:28:22 +0800 Subject: [PATCH] Fix: close http Response body on provider (#1154) --- adapters/provider/vehicle.go | 1 + component/vmess/h2.go | 1 + tunnel/connection.go | 2 ++ 3 files changed, 4 insertions(+) diff --git a/adapters/provider/vehicle.go b/adapters/provider/vehicle.go index 175f50ce..13d898fc 100644 --- a/adapters/provider/vehicle.go +++ b/adapters/provider/vehicle.go @@ -107,6 +107,7 @@ func (h *HTTPVehicle) Read() ([]byte, error) { if err != nil { return nil, err } + defer resp.Body.Close() buf, err := ioutil.ReadAll(resp.Body) if err != nil { diff --git a/component/vmess/h2.go b/component/vmess/h2.go index b814ae9b..2c4c47fa 100644 --- a/component/vmess/h2.go +++ b/component/vmess/h2.go @@ -46,6 +46,7 @@ func (hc *h2Conn) establishConn() error { }, } + // it will be close at : `func (hc *h2Conn) Close() error` res, err := hc.ClientConn.RoundTrip(&req) if err != nil { return err diff --git a/tunnel/connection.go b/tunnel/connection.go index 1e8ee1df..15a62555 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -34,6 +34,8 @@ func handleHTTP(request *inbound.HTTPAdapter, outbound net.Conn) { } handleResponse: + // resp will be closed after we call resp.Write() + // see https://golang.org/pkg/net/http/#Response.Write resp, err := http.ReadResponse(outboundReader, req) if err != nil { break