Repository navigation
Conversation
b76fd5d to
e5aa423
Compare
This comment has been minimized.
This comment has been minimized.
|
Review posted | Chat Review history
deep-review v0.13.0 | Round 2 | Last posted: Round 2, 10 findings (2 P2, 4 P3, 2 Nit, 2 Note), COMMENT. Review Finding inventoryFindings
Contested and acknowledgedCRF-1 (P3, close.go:92) - Close doc says additional calls are no-ops
CRF-4 (P3, close.go:130) - CloseNow doc silent on repeated calls
Round logRound 1Panel. 1 P2, 3 P3, 2 Nit, 2 Note new. 1 pre-existing Note dropped. Reviewed against d099e16..e5aa423. Panel: Bisky, Hisoka, Mafu-san, Mafuuu, Pariston, Ging-Go, Gon, Leorio, Takumi, Meruem, Killua, Chopper. Round 2Restructure round (internal/libclose added, Close/CloseNow rewritten as wrappers, description rewritten). Churn guard PROCEED: CRF-3, 5, 6, 7, 8, 9 addressed; CRF-1, CRF-4 contested. Netero: 1 P3 (CRF-10), 2 OOS. Panel: Pariston, Mafuuu, Ging-Go, Takumi, Ryosuke, Melody, Killua, Bisky, Gon, Leorio, Kite (wildcard). Size 11 exceeds focused target: specialists Ging-Go, Takumi, Ryosuke, Melody, Killua triggered; Gon and Leorio mandatory on restructure; Leorio also contested. No previous agents existed in this orchestrator chat, so Netero, Pariston and Leorio were new agents reading round-1 outputs. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
e5aa423 to
21b8e2a
Compare
21b8e2a to
60b4584
Compare
This comment has been minimized.
This comment has been minimized.
Close and CloseNow returned a wrapped net.ErrClosed when the internal read loop or write path won the casClosing race before the user-facing call. The defer that suppresses net.ErrClosed was only registered on the CAS winner path. Separate user-facing close tracking from internal close coordination. A userClosed atomic tracks whether the user has called Close/CloseNow before. Combined with isClosed, this gives three distinct behaviors: - First user call, close in progress or peer closed: nil. - Concurrent user calls while close is in progress: nil, returns instantly without blocking. - User call after close has fully completed: net.ErrClosed.
When the read or write path closed the connection first, for example after the peer's close frame, the user's first Close or CloseNow returned a wrapped net.ErrClosed. The first user call now returns nil in that case, and library code that closes the connection (CloseRead and NetConn reads) uses an internal close so it does not count as that call.
On Wasm, the user's first Close returned a wrapped net.ErrClosed after the browser or library code had already closed the connection, the same failure as the native fix. Close now applies the same first-call rule, and the read limit, read timeout, CloseRead and finalizer paths use an internal close. TestWasm gains a server mode that closes first.
60b4584 to
aca4625
Compare
wsjson.Read closed the connection with the public Close when the message was not valid JSON, so the application's first Close or CloseNow returned net.ErrClosed. wsjson cannot call the unexported closeWithHandshake, so package websocket stores it in internal/libclose during initialization and wsjson.Read calls it from there.
|
/coder-agents-review Please limit the review to P0, P1, P2 issues only. Include only highly relevant P3 issues.
|
|
Chat: Review in progress (13/13 reviewers complete) | View chat
|
There was a problem hiding this comment.
This round reviews the rewritten branch, which routes library closes through internal closeWithHandshake and closeWithoutHandshake so the user's first Close or CloseNow returns nil after a library or peer close. As requested, it posts P0 to P2 findings and only the most relevant P3 findings: 1 P2, 2 P3.
The new tests cover the bug from round 1, and the naming, comment, description and isClosed race findings are addressed. The CloseNow doc finding is closed. The Close doc finding is still open; see the reply below.
Out of scope (needs a ticket or explicit acceptance by a human):
dial_test.go:48: thebadTLScase dials the external hosttotallyfake.nhooyr.io, sogo test -race ./...failsTestMainwith a goroutine leak on networks where that dial leaves TLS goroutines running (reproduced on head and base).ws_js.go:430: WasmCloseReadsendsStatusPolicyViolation"unexpected data message" whenc.readreturns an error andStatusGoingAwaywhen it receives a data message, the inverse of nativeread.go:81, so a Wasm peer that sends data afterCloseReadreceives 1001 instead of 1008.
In reply to PRR_kwDOCJ5FYc8AAAABAxB24A:
The close.go:93 doc finding is still open. The behavior it misstates predates this PR, but this PR adds the first-call guarantee (close.go:110, close.go:163, ws_js.go:240) and the doc does not state it, so godoc readers cannot learn the contract this PR ships. Updating the text records current behavior and does not decide the repeated-Close question. Suggested text for native Close, Wasm Close and CloseNow:
// If the connection is already closing or closed, for example after a read
// returned the peer's close frame, the first call to Close or CloseNow waits
// for the close to finish and returns nil. A later call that finds the
// connection closing or closed waits, then returns an error wrapping
// net.ErrClosed.🤖
🤖 This review was automatically generated with Coder Agents.
The first call to
CloseorCloseNowcould returnfailed to close WebSocket: use of closed network connectioneven when the connection had closed normally. This happens when the library closes the connection before the user callsClose: after the peer's close frame is read, whenCloseReadreceives a data message, when aNetConnreads a message of the wrong type, or whenwsjson.Readreceives a message that is not valid JSON. On Wasm, the same error appeared after the browser closed the connection. Code that reads until a close error and then callsClosetherefore failed on every normal peer close.Now the first user call to
CloseorCloseNowreturns nil in these cases. On native, it still waits until the connection, and theCloseReadgoroutine if any, have finished closing. On Wasm, it waits until the browser has closed the connection, but not for theCloseReadgoroutine. Later calls behave as before: a call that closes the connection returns the result of that close, and a call that finds the connection closing or closed waits, then returnsnet.ErrClosed. If a later call closes the connection before the first call starts closing it, the first call also returns nil.Library code that closes the connection, including
wsjson.Read, now calls an internal function instead ofClose, so it does not use up the user's first call. On Wasm this covers the error event, failed writes, the read limit, the read timeout,CloseReadand the finalizer.TestConn/firstCloseAfterLibraryCloseandTestWasmFirstCloseAfterPeerClosefail on master with the error above and pass on this branch.go test -race ./...andTestWasmpass.Refs coder/internal#1541
Decision log
net.ErrClosedinto nil. A later call that finds the connection closing or closed keeps returningnet.ErrClosed, because repeated-Closebehavior is a separate decision.net.ErrClosedafter a library close finished.Close, they would use up the user's first call and the user's ownClosewould still fail; thecloseReadDataMessage,netConnUnexpectedTypeandwsjsonInvalidJSONsubtests cover this.wsjsonis a separate package and cannot call the unexported internal close, so package websocket stores it ininternal/libcloseduring initialization, andwsjson.Readcalls it from there. This adds no public API.CloseReaddefers the internal close withStatusGoingAway, which is what WasmCloseNowsends.Closedecision.closeReadDataMessagesubtests take 15s because theCloseReadgoroutine waits for its own exit until the 15s timeout. Master has the same wait; this PR does not change it. fix: stop CloseRead from waiting on itself #607 removes the wait, and it conflicts with this PR where theCloseReadgoroutine closes the connection inread.go.TestWasmserver closes first when the client requests theclosesubprotocol.