fix: chrome requests hanging over port-forward (#4588)

This commit is contained in:
Colin Adler
2022-10-17 11:45:29 -05:00
committed by GitHub
parent d2ee18c14f
commit 29acd25b4e
2 changed files with 19 additions and 6 deletions
+13 -3
View File
@@ -879,12 +879,22 @@ func (r *reconnectingPTY) Close() {
// after one or both of them are done writing. If the context is canceled, both
// of the connections will be closed.
func Bicopy(ctx context.Context, c1, c2 io.ReadWriteCloser) {
defer c1.Close()
defer c2.Close()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
defer func() {
_ = c1.Close()
_ = c2.Close()
}()
var wg sync.WaitGroup
copyFunc := func(dst io.WriteCloser, src io.Reader) {
defer wg.Done()
defer func() {
wg.Done()
// If one side of the copy fails, ensure the other one exits as
// well.
cancel()
}()
_, _ = io.Copy(dst, src)
}