Make sure that closing one direction closes the other, too.

This commit is contained in:
Christian Speckner 2025-01-31 16:26:13 +01:00
parent d710683181
commit da52840a27
4 changed files with 22 additions and 56 deletions

24
http.go
View file

@ -10,8 +10,6 @@ import (
"net"
"net/http"
"strings"
"github.com/sourcegraph/conc"
)
const proxyAuthHeaderKey = "Proxy-Authorization"
@ -131,17 +129,19 @@ func (s *HTTPServer) serve(conn net.Conn) {
log.Println("dial proxy failed: peer nil")
return
}
go func() {
wg := conc.NewWaitGroup()
wg.Go(func() {
_, err = io.Copy(conn, peer)
_ = conn.Close()
})
wg.Go(func() {
_, err = io.Copy(peer, conn)
_ = peer.Close()
})
wg.Wait()
defer conn.Close()
defer peer.Close()
io.Copy(conn, peer)
}()
go func() {
defer conn.Close()
defer peer.Close()
io.Copy(peer, conn)
}()
}