aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris O'Hara <cohara87@gmail.com>2023-08-16 11:14:53 +1000
committerGopher Robot <gobot@golang.org>2023-08-18 18:00:35 +0000
commit70aa116c4afe064254252a33beb82977ae8df087 (patch)
tree02037a0302e8dfd90705dfe5b4ce7b8ed02d6564
parent31c5a236bc473756535ae163bb68242926b5eed7 (diff)
downloadgo-70aa116c4afe064254252a33beb82977ae8df087.tar.gz
go-70aa116c4afe064254252a33beb82977ae8df087.zip
[release-branch.go1.21] 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. Updates #61820. Fixes #61821. Change-Id: I375145c1a1d03ad45c44f528da3347397e6dcb01 Reviewed-on: https://go-review.googlesource.com/c/go/+/519895 Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> (cherry picked from commit 795e779610cd1ef8ad4c137c067a23ace1190115) Reviewed-on: https://go-review.googlesource.com/c/go/+/520955 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
-rw-r--r--src/runtime/internal/wasitest/tcpecho_test.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/runtime/internal/wasitest/tcpecho_test.go b/src/runtime/internal/wasitest/tcpecho_test.go
index c15da86f35..11373955f3 100644
--- a/src/runtime/internal/wasitest/tcpecho_test.go
+++ b/src/runtime/internal/wasitest/tcpecho_test.go
@@ -20,13 +20,18 @@ func TestTCPEcho(t *testing.T) {
t.Skip()
}
- // We're unable to pass port 0 here (let the OS choose a spare port).
- // Although wasmtime accepts port 0, and testdata/main.go successfully
- // listens, there's no way for this test case to query the chosen port
+ // We're unable to use port 0 here (let the OS choose a spare port).
+ // Although the WASM runtime accepts port 0, and the WASM module listens
+ // successfully, there's no way for this test to query the selected port
// so that it can connect to the WASM module. The WASM module itself
// cannot access any information about the socket due to limitations
- // with WASI preview 1 networking, and wasmtime does not log the address
- // when you preopen a socket. Instead, we probe for a free port here.
+ // with WASI preview 1 networking, and the WASM runtimes do not log the
+ // port when you pre-open a socket. So, we probe for a free port here.
+ // Given there's an unavoidable race condition, the test is disabled by
+ // default.
+ if os.Getenv("GOWASIENABLERACYTEST") != "1" {
+ t.Skip("skipping WASI test with unavoidable race condition")
+ }
var host string
port := rand.Intn(10000) + 40000
for attempts := 0; attempts < 10; attempts++ {
@@ -64,7 +69,7 @@ func TestTCPEcho(t *testing.T) {
var conn net.Conn
var err error
- for attempts := 0; attempts < 5; attempts++ {
+ for {
conn, err = net.Dial("tcp", host)
if err == nil {
break