comments + fix Forward method

This commit is contained in:
Jose Garcia 2021-09-09 20:11:45 +00:00 committed by GitHub
parent 920f793c6d
commit efe519cb7a

View file

@ -80,9 +80,7 @@ func (fwd *PortForwarder) Forward(ctx context.Context, conn io.ReadWriteCloser)
// Create buffered channel so that send doesn't get stuck after context cancellation.
errc := make(chan error, 1)
go func() {
if err := fwd.handleConnection(ctx, id, conn); err != nil {
errc <- err
}
errc <- fwd.handleConnection(ctx, id, conn)
}()
return awaitError(ctx, errc)
}
@ -131,7 +129,9 @@ func (fwd *PortForwarder) handleConnection(ctx context.Context, id channelID, co
go copyConn(conn, channel)
go copyConn(channel, conn)
// wait until context is cancelled or both copies are done
// Wait until context is cancelled or both copies are done.
// Discard errors from io.Copy; they should not cause (e.g.) ForwardToListener to fail.
// TODO: how can we proxy errors from Copy so that each peer can distinguish an error from a short file?
for i := 0; ; {
select {
case <-ctx.Done():