Repository navigation
Conversation
wsCmd.Close called SetWriteDeadline on the connection while the adapter's write loop could still be inside WriteMessage. gorilla's WriteControl takes its own deadline and is safe to call alongside another writer, so the SetWriteDeadline call is dropped. The TTY resize goroutine read the os.Stdin global 10ms after start, after Start had already returned. It now captures os.Stdin before Start returns and exits early if the command finishes first. Both are covered by tests that fail under -race without the change. Fixes #48
|
Reviewed this against a local checkout of the branch. The change itself looks correct and the reasoning in the description holds up. I confirmed both tests are real regression tests: reverting Two things worth considering, neither blocking: 1.
|
proxyConn.Close called SetWriteDeadline outside writeMu, racing with a concurrent Write inside WriteMessage, the same pattern as wsCmd.Close. net.Conn allows Close while Write is in progress, so drop the call and rely on the deadline WriteControl already takes. The TTY resize test's server exited before the goroutine's 10ms delay, so it only covered the early return, not the stdin capture. Delay the exit frame so the goroutine reads stdin while the command runs. That also showed the goroutine calling Fd() on an *os.File the caller may close afterwards, so capture the descriptor before Start returns. Restore os.Stdin with t.Cleanup. Each new or changed test fails under -race with its fix reverted.
|
Thanks for the careful review. Both points are in 81018e3:
|
Fixes #48
Both races from the issue, reproduced in this repo with
go test -race:wsCmd.Closevs the write loop.ClosecalledSetWriteDeadlineon the connection whilewsAdapter.writeLoopcould still be insideWriteMessage. gorilla'sWriteControlalready takes a deadline argument and is documented as safe to call concurrently with other methods, so I dropped theSetWriteDeadlinecall and kept theWriteControl+Close.TTY resize goroutine reading
os.Stdin. The goroutine read theos.Stdinglobal 10ms after start, afterStarthad returned to the caller. It now captures the stdin descriptor instart()beforestartChanis signaled, and usually returns early ifdoneChancloses before the 10ms timer fires (if both are ready,selectmay still proceed, which is harmless).proxyConn.ClosevsproxyConn.Write(from review). Same pattern inproxy.go:ClosecalledSetWriteDeadlineoutsidewriteMuwhile aWritecould be insideWriteMessage. Same fix.Tests: added
websocket_race_test.gowith one test per race, each against anhttptestwebsocket server. The TTY test delays the exit frame past the 10ms timer so the goroutine actually reads stdin. Before the change both tests failed under-racewith the stacks from the issue (websocket.go:690vs:754, and:272vs the test restoringos.Stdin). Each test fails under-racewith its fix reverted (including reverting only the stdin capture). After the change,go test -race -count=10on the three tests andgo test -race ./...pass, andgolangci-lint run(v2.11.3, repo config) reports 0 issues. I didn't run the integration tests since they need a Sprites token.