Skip to content

Commit

Permalink
Fix connection leak when write failed but dial success.
Browse files Browse the repository at this point in the history
close the connection before return.
  • Loading branch information
zltl committed Jan 25, 2022
1 parent 5ea9529 commit d91707b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func newDirectHTTPConn(c *Client, network, address string) (net.Conn, error) {

_, err = io.WriteString(conn, "CONNECT "+path+" HTTP/1.0\n\n")
if err != nil {
// Dial() success but Write() failed here, close the successfully
// created conn before return.
conn.Close()

log.Errorf("failed to make CONNECT: %v", err)
return nil, err
}
Expand Down

0 comments on commit d91707b

Please sign in to comment.