From 94b91661cc68b200e30e809d8c26b41a7f37c1af Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 2 Sep 2021 14:30:19 -0400 Subject: [PATCH] don't forget to close conn in case of sharing error --- port_forwarder.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/port_forwarder.go b/port_forwarder.go index 4391ef55c..2d1217c24 100644 --- a/port_forwarder.go +++ b/port_forwarder.go @@ -18,6 +18,12 @@ type PortForwarder struct { // between the local port and the container's remote port over the // specified Live Share session. The name describes the purpose of the // remote port or service. +// +// TODO(adonovan): the localPort param is redundant wrt ForwardWithConn. +// Simpler: do away with the NewPortForwarder type altogether: +// +// - ForwardToLocalPort(ctx, session, name, remote, local) +// - ForwardToConnection(ctx, session, name, remote, conn) func NewPortForwarder(session *Session, name string, localPort, remotePort int) *PortForwarder { return &PortForwarder{ session: session, @@ -74,6 +80,7 @@ func (fwd *PortForwarder) Forward(ctx context.Context) (err error) { func (fwd *PortForwarder) ForwardWithConn(ctx context.Context, conn io.ReadWriteCloser) error { id, err := fwd.shareRemotePort(ctx) if err != nil { + conn.Close() return err }