Skip to content

Commit

Permalink
Merge pull request #29 from rancher-sandbox/fix-kube-open-connections
Browse files Browse the repository at this point in the history
Ensure proper closure of upstream connection in Pipe function
  • Loading branch information
jandubois authored Aug 9, 2024
2 parents 6abacdc + a8c868a commit 0e89b24
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/utils/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ func Pipe(conn net.Conn, upstreamAddr string) {
logrus.Errorf("Failed to dial upstream %s: %s", upstreamAddr, err)
return
}
defer upstream.Close()

go func() {
if _, err := io.Copy(upstream, conn); err != nil {
logrus.Debugf("Error copying to upstream: %s", err)
}
if err = upstream.Close(); err != nil {
logrus.Debugf("error closing connection while writing to upstream: %s", err)
}
}()

if _, err := io.Copy(conn, upstream); err != nil {
logrus.Debugf("Error copying from upstream: %s", err)
}
if err = upstream.Close(); err != nil {
logrus.Debugf("error closing connection: %s", err)
}
}

0 comments on commit 0e89b24

Please sign in to comment.