Skip to content

Commit

Permalink
Fix interrupted pending writes on socket write shutdown from eager close
Browse files Browse the repository at this point in the history
Signed-off-by: Jason T. Greene <[email protected]>
  • Loading branch information
n1hility committed Dec 3, 2022
1 parent 19b9c49 commit 7bab90c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/sshclient/ssh_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"runtime"
"strings"
"sync"
"time"

"github.com/containers/gvisor-tap-vsock/pkg/fs"
Expand Down Expand Up @@ -228,14 +229,22 @@ func acceptConnection(ctx context.Context, listener net.Listener, bastion *Basti
return nil // eat
}

go forward(src, dest)
go forward(dest, src)
complete := new(sync.WaitGroup)
complete.Add(2)
go forward(src, dest, complete)
go forward(dest, src, complete)

go func() {
complete.Wait()
src.Close()
dest.Close()
}()

return nil
}

func forward(src io.ReadCloser, dest CloseWriteStream) {
defer src.Close()
func forward(src io.ReadCloser, dest CloseWriteStream, complete *sync.WaitGroup) {
defer complete.Done()
_, _ = io.Copy(dest, src)

// Trigger an EOF on the other end
Expand Down

0 comments on commit 7bab90c

Please sign in to comment.