Skip to content

Commit 0413af4

Browse files
authored
rpc: fix a flaky test of the websocket (#33002)
Found in https://github.com/ethereum/go-ethereum/actions/runs/17803828253/job/50611300621?pr=32585 ``` --- FAIL: TestClientCancelWebsocket (0.33s) panic: read tcp 127.0.0.1:36048->127.0.0.1:38643: read: connection reset by peer [recovered, repanicked] goroutine 15 [running]: testing.tRunner.func1.2({0x98dd20, 0xc0005b0100}) /opt/actions-runner/_work/_tool/go/1.25.1/x64/src/testing/testing.go:1872 +0x237 testing.tRunner.func1() /opt/actions-runner/_work/_tool/go/1.25.1/x64/src/testing/testing.go:1875 +0x35b panic({0x98dd20?, 0xc0005b0100?}) /opt/actions-runner/_work/_tool/go/1.25.1/x64/src/runtime/panic.go:783 +0x132 github.com/ethereum/go-ethereum/rpc.httpTestClient(0xc0001dc1c0?, {0x9d5e40, 0x2}, 0xc0002bc1c0) /opt/actions-runner/_work/go-ethereum/go-ethereum/rpc/client_test.go:932 +0x2b1 github.com/ethereum/go-ethereum/rpc.testClientCancel({0x9d5e40, 0x2}, 0xc0001dc1c0) /opt/actions-runner/_work/go-ethereum/go-ethereum/rpc/client_test.go:356 +0x15f github.com/ethereum/go-ethereum/rpc.TestClientCancelWebsocket(0xc0001dc1c0?) /opt/actions-runner/_work/go-ethereum/go-ethereum/rpc/client_test.go:319 +0x25 testing.tRunner(0xc0001dc1c0, 0xa07370) /opt/actions-runner/_work/_tool/go/1.25.1/x64/src/testing/testing.go:1934 +0xea created by testing.(*T).Run in goroutine 1 /opt/actions-runner/_work/_tool/go/1.25.1/x64/src/testing/testing.go:1997 +0x465 FAIL github.com/ethereum/go-ethereum/rpc 0.371s ``` In `testClientCancel` we wrap the server listener in `flakeyListener`, which schedules an unconditional close of every accepted connection after a random delay, if the random delay is zero then the timer fires immediately, and then the http client paniced of connection reset by peer. Here we add a minimum 10ms to ensure the timeout won't fire immediately. Signed-off-by: jsvisa <[email protected]>
1 parent f1be215 commit 0413af4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rpc/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ func (l *flakeyListener) Accept() (net.Conn, error) {
973973

974974
c, err := l.Listener.Accept()
975975
if err == nil {
976-
timeout := time.Duration(rand.Int63n(int64(l.maxKillTimeout)))
976+
timeout := max(time.Millisecond*10, time.Duration(rand.Int63n(int64(l.maxKillTimeout))))
977977
time.AfterFunc(timeout, func() {
978978
log.Debug(fmt.Sprintf("killing conn %v after %v", c.LocalAddr(), timeout))
979979
c.Close()

0 commit comments

Comments
 (0)