Skip to content

Commit 83cbc02

Browse files
authored
Merge pull request #3708 from AkihiroSuda/fix-3685-2
CI: test and fix portfwd issue (`w3m -dump` hangs)
2 parents 9641e25 + 6ca9e7f commit 83cbc02

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ jobs:
264264
# QEMU: required by Lima itself
265265
# bash: required by test-templates.sh (OS version of bash is too old)
266266
# coreutils: required by test-templates.sh for the "timeout" command
267-
run: brew install qemu bash coreutils
267+
# w3m : required by test-templates.sh for port forwarding tests
268+
run: brew install qemu bash coreutils w3m
268269
- name: "Adjust LIMACTL_CREATE_ARGS"
269270
run: echo "LIMACTL_CREATE_ARGS=${LIMACTL_CREATE_ARGS} --vm-type=qemu" >>$GITHUB_ENV
270271
- name: "Inject `no_timer_check` to kernel cmdline"
@@ -331,7 +332,7 @@ jobs:
331332
- name: Install test dependencies
332333
run: |
333334
sudo apt-get update
334-
sudo apt-get install -y --no-install-recommends ovmf qemu-system-x86 qemu-utils
335+
sudo apt-get install -y --no-install-recommends ovmf qemu-system-x86 qemu-utils w3m
335336
sudo modprobe kvm
336337
# `sudo usermod -aG kvm $(whoami)` does not take an effect on GHA
337338
sudo chown $(whoami) /dev/kvm
@@ -430,7 +431,7 @@ jobs:
430431
with:
431432
template: templates/default.yaml
432433
- name: Install test dependencies
433-
run: brew install qemu bash coreutils
434+
run: brew install qemu bash coreutils w3m
434435
- name: Install socket_vmnet
435436
env:
436437
SOCKET_VMNET_VERSION: v1.2.0
@@ -525,7 +526,7 @@ jobs:
525526
with:
526527
template: templates/${{ matrix.template }}
527528
- name: Install test dependencies
528-
run: brew install bash coreutils
529+
run: brew install bash coreutils w3m
529530
- name: Uninstall qemu
530531
run: brew uninstall --ignore-dependencies --force qemu
531532
- name: Test

hack/test-templates.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,15 @@ if [[ -n ${CHECKS["port-forwards"]} ]]; then
381381
limactl shell "$NAME" $sudo $CONTAINER_ENGINE rm -f nginx
382382
fi
383383
fi
384+
if [[ ${NAME} != "alpine"* && ${NAME} != "wsl2"* ]] && command -v w3m >/dev/null; then
385+
INFO "Testing https://github.com/lima-vm/lima/issues/3685 ([gRPC portfwd] client connection is not closed immediately when server closed the connection)"
386+
# 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
388+
limactl shell "$NAME" systemd-run --user python3 -m http.server 3685
389+
# curl is not enough to reproduce https://github.com/lima-vm/lima/issues/3685
390+
# `w3m -dump` exits with status code 0 even on "Can't load" error.
391+
timeout 30s bash -euxc "until w3m -dump http://localhost:3685 | grep -v \"w3m: Can't load\"; do sleep 3; done"
392+
fi
384393
fi
385394
set +x
386395
fi

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)