Skip to content

Commit 6a612d9

Browse files
committed
cleanup: remove package bicopy
This has a single caller that doesn't even use the full interface. This changes behavior in that errors are no longer ignored. While I'm here: remove nonsensical handling of `io.EOF` returned from `io.Copy` which can never happen per the latter's documentation. Signed-off-by: Tamir Duberstein <[email protected]>
1 parent ca778e3 commit 6a612d9

File tree

3 files changed

+16
-90
lines changed

3 files changed

+16
-90
lines changed

pkg/bicopy/bicopy.go

Lines changed: 0 additions & 81 deletions
This file was deleted.

pkg/hostagent/port_darwin.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package hostagent
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"io"
68
"net"
79
"os"
810
"path/filepath"
911
"strconv"
1012
"strings"
1113

12-
"github.com/lima-vm/lima/pkg/bicopy"
1314
"github.com/lima-vm/lima/pkg/portfwd"
1415
"github.com/lima-vm/sshocker/pkg/ssh"
1516
"github.com/sirupsen/logrus"
17+
"golang.org/x/sync/errgroup"
1618
)
1719

1820
// forwardTCP is not thread-safe.
@@ -149,8 +151,19 @@ func (plf *pseudoLoopbackForwarder) forward(ac *net.TCPConn) error {
149151
return err
150152
}
151153
defer unixConn.Close()
152-
bicopy.Bicopy(ac, unixConn, nil)
153-
return nil
154+
155+
g, _ := errgroup.WithContext(context.Background())
156+
157+
g.Go(func() error {
158+
_, err := io.Copy(unixConn, ac)
159+
return errors.Join(err, unixConn.CloseRead(), ac.CloseWrite())
160+
})
161+
g.Go(func() error {
162+
_, err := io.Copy(ac, unixConn)
163+
return errors.Join(err, ac.CloseRead(), unixConn.CloseWrite())
164+
})
165+
166+
return g.Wait()
154167
}
155168

156169
func (plf *pseudoLoopbackForwarder) Close() error {

pkg/portfwd/client.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,10 @@ func HandleTCPConnection(ctx context.Context, client *guestagentclient.GuestAgen
2929
rw := &GrpcClientRW{stream: stream, id: id, addr: guestAddr}
3030
g.Go(func() error {
3131
_, err := io.Copy(rw, conn)
32-
if errors.Is(err, io.EOF) {
33-
return nil
34-
}
3532
return err
3633
})
3734
g.Go(func() error {
3835
_, err := io.Copy(conn, rw)
39-
if errors.Is(err, io.EOF) {
40-
return nil
41-
}
4236
return err
4337
})
4438

0 commit comments

Comments
 (0)