Skip to content

Commit 99944fc

Browse files
committed
portfwdserver: use tcpproxy to fix w3m -dump issue
Fix issue 3685 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 0678d67 commit 99944fc

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

hack/test-templates.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,10 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
381381
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
382382
fi
383383
fi
384-
if [[ ${NAME} != "alpine"* ]]; then
384+
if [[ ${NAME} != "alpine"* && ${NAME} != "wsl2"* ]]; then
385385
INFO "Testing https://github.com/lima-vm/lima/issues/3685 ([gRPC portfwd] client connection is not closed immediately when server closed the connection)"
386386
# Skip the test on Alpine, as systemd-run is missing
387+
# Skip the test on WSL2, as port forwarding is half broken https://github.com/lima-vm/lima/pull/3686#issuecomment-3034842616
387388
limactl shell "$NAME" systemd-run --user python3 -m http.server 3685
388389
# curl is not enough to reproduce https://github.com/lima-vm/lima/issues/3685
389390
# `w3m -dump` exits with status code 0 even on "Can't load" error.

pkg/portfwdserver/server.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
package portfwdserver
55

66
import (
7+
"context"
78
"errors"
89
"io"
910
"net"
11+
"os"
12+
"strings"
1013
"time"
1114

15+
"github.com/containers/gvisor-tap-vsock/pkg/tcpproxy"
16+
1217
"github.com/lima-vm/lima/pkg/bicopy"
1318
"github.com/lima-vm/lima/pkg/guestagent/api"
1419
)
@@ -35,7 +40,23 @@ func (s *TunnelServer) Start(stream api.GuestService_TunnelServer) error {
3540
return err
3641
}
3742
rw := &GRPCServerRW{stream: stream, id: in.Id}
38-
bicopy.Bicopy(rw, conn, nil)
43+
44+
// FIXME: consolidate bicopy and tcpproxy into one
45+
//
46+
// The bicopy package does not seem to work with `w3m -dump`:
47+
// https://github.com/lima-vm/lima/issues/3685
48+
//
49+
// However, the tcpproxy package can't pass the CI for WSL2 (experimental):
50+
// https://github.com/lima-vm/lima/pull/3686#issuecomment-3034842616
51+
if wsl2, _ := seemsWSL2(); wsl2 {
52+
bicopy.Bicopy(rw, conn, nil)
53+
} else {
54+
proxy := tcpproxy.DialProxy{DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
55+
return conn, nil
56+
}}
57+
proxy.HandleConn(rw)
58+
}
59+
3960
return nil
4061
}
4162

@@ -83,3 +104,13 @@ func (g *GRPCServerRW) SetReadDeadline(_ time.Time) error {
83104
func (g *GRPCServerRW) SetWriteDeadline(_ time.Time) error {
84105
return nil
85106
}
107+
108+
// seemsWSL2 returns whether lima.env contains LIMA_CIDATA_VMTYPE=wsl2 .
109+
// This is a temporary workaround and has to be removed.
110+
func seemsWSL2() (bool, error) {
111+
b, err := os.ReadFile("/mnt/lima-cidata/lima.env")
112+
if err != nil {
113+
return false, err
114+
}
115+
return strings.Contains(string(b), "LIMA_CIDATA_VMTYPE=wsl2"), nil
116+
}

0 commit comments

Comments
 (0)