Skip to content

Commit f946103

Browse files
committed
portfwdserver: fix half-close
Fix issue 3685 Similar to 3684 Signed-off-by: Akihiro Suda <[email protected]>
1 parent d877648 commit f946103

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pkg/portfwdserver/server.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
package portfwdserver
55

66
import (
7+
"context"
78
"errors"
89
"io"
910
"net"
1011
"time"
1112

12-
"github.com/lima-vm/lima/pkg/bicopy"
13+
"github.com/containers/gvisor-tap-vsock/pkg/tcpproxy"
14+
1315
"github.com/lima-vm/lima/pkg/guestagent/api"
1416
)
1517

@@ -29,13 +31,13 @@ func (s *TunnelServer) Start(stream api.GuestService_TunnelServer) error {
2931
return err
3032
}
3133

32-
// We simply forward data form GRPC stream to net.Conn for both tcp and udp. So simple proxy is sufficient
33-
conn, err := net.Dial(in.Protocol, in.GuestAddr)
34-
if err != nil {
35-
return err
36-
}
3734
rw := &GRPCServerRW{stream: stream, id: in.Id}
38-
bicopy.Bicopy(rw, conn, nil)
35+
proxy := tcpproxy.DialProxy{DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
36+
// We simply forward data form GRPC stream to net.Conn for both tcp and udp. So simple proxy is sufficient
37+
var d net.Dialer
38+
return d.DialContext(ctx, in.Protocol, in.GuestAddr)
39+
}}
40+
proxy.HandleConn(rw)
3941
return nil
4042
}
4143

0 commit comments

Comments
 (0)