Skip to content

Commit 795e779

Browse files
chrisojohanbrandhorst
authored andcommitted
runtime/internal/wasitest: skip racy TCP echo test
The wasip1 TCP echo test introduced in CL 493358 has a race condition with port selection. The test runner probes for a free port and then asks the WASM runtime to listen on the port, which may be taken by another process in the interim. Due to limitations with WASI preview 1, the guest is unable to query the port it's listening on. The test cannot ask the WASM runtime to listen on port 0 (choose a free port) since there's currently no way for the test to query the selected port and connect to it. Given the race condition is unavoidable, this test is now disabled by default and requires opt-in via an environment variable. This commit also eliminates the hard-coded connection timeout. Fixes #61820. Change-Id: I375145c1a1d03ad45c44f528da3347397e6dcb01 Reviewed-on: https://go-review.googlesource.com/c/go/+/519895 Run-TryBot: Johan Brandhorst-Satzkorn <[email protected]> Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent e8a767b commit 795e779

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/runtime/internal/wasitest/tcpecho_test.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ func TestTCPEcho(t *testing.T) {
2020
t.Skip()
2121
}
2222

23-
// We're unable to pass port 0 here (let the OS choose a spare port).
24-
// Although wasmtime accepts port 0, and testdata/main.go successfully
25-
// listens, there's no way for this test case to query the chosen port
23+
// We're unable to use port 0 here (let the OS choose a spare port).
24+
// Although the WASM runtime accepts port 0, and the WASM module listens
25+
// successfully, there's no way for this test to query the selected port
2626
// so that it can connect to the WASM module. The WASM module itself
2727
// cannot access any information about the socket due to limitations
28-
// with WASI preview 1 networking, and wasmtime does not log the address
29-
// when you preopen a socket. Instead, we probe for a free port here.
28+
// with WASI preview 1 networking, and the WASM runtimes do not log the
29+
// port when you pre-open a socket. So, we probe for a free port here.
30+
// Given there's an unavoidable race condition, the test is disabled by
31+
// default.
32+
if os.Getenv("GOWASIENABLERACYTEST") != "1" {
33+
t.Skip("skipping WASI test with unavoidable race condition")
34+
}
3035
var host string
3136
port := rand.Intn(10000) + 40000
3237
for attempts := 0; attempts < 10; attempts++ {
@@ -64,7 +69,7 @@ func TestTCPEcho(t *testing.T) {
6469

6570
var conn net.Conn
6671
var err error
67-
for attempts := 0; attempts < 5; attempts++ {
72+
for {
6873
conn, err = net.Dial("tcp", host)
6974
if err == nil {
7075
break

0 commit comments

Comments
 (0)