Close() aborts the closing handshake when an in-flight Ping arrives after Close is sent
維護者通常 3 天內回覆
還沒有人認領這個 Issue。
- #595 來自 @Mohith26 —— 已關閉,未合併
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- go
- 領域
- networking
研究方向
Start by reading writeFrame, handleControl, and waitCloseHandshake, then run the raw-socket reproduction described in the issue to confirm the missing Pong and unread peer Close. Check the existing close and Ping tests for nearby coverage. Done means a Ping received after sending Close gets the required Pong, the peer's Close is consumed, and the regression is covered by a test.
由索引模型根據 Issue 內容生成。
描述
Description
Conn.Close does not complete the RFC 6455 closing handshake when a Ping that was already on the wire arrives after this endpoint has sent Close.
What happens:
writeClosesetscloseSentErr.waitCloseHandshake→readLoop→handleControlseesopPingand callswriteControl(opPong, …).writeFramereturnsnet.ErrClosedbecausecloseSentErr != nil(every opcode is refused after Close).- That error aborts the drain before the peer's Close is read.
Close's defer turnserrors.Is(err, net.ErrClosed)intonil, so the caller sees success.- No Pong is written; the peer's Close is never consumed; TCP is closed anyway.
Data frames and a peer Close alone in the same state are fine (waitCloseHandshake discards data and returns on Close). Only Ping breaks the drain.
Spec
RFC 6455 §5.5.2:
Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in response, unless it already received a Close frame.
At this point Close has been sent, not received, so a Pong is required. §5.5.1 forbids further data frames after Close; Pong is a control frame. §7.1.2 expects the endpoint to finish sending and receiving Close before tearing down TCP.
Reproduction
Raw-socket peer that lets the library send Close first, then writes Ping+Close without having read that Close (simulates frames written before the peer saw Close):
// library side
c, _ := websocket.Accept(w, r, &websocket.AcceptOptions{
OnPingReceived: func(ctx context.Context, payload []byte) bool { return true },
})
_ = c.Write(ctx, websocket.MessageText, []byte("ready"))
time.Sleep(100 * time.Millisecond)
err := c.Close(websocket.StatusNormalClosure, "server-close")
// err == nil even when the peer's Close was never read
# peer: after reading "ready", wait until library Close is on the wire, then
# write Ping + Close without reading
sock.send(ping_frame)
sock.send(close_frame(1000))
# observe: library Close arrives, TCP closes, **no Pong**
Observed on master @ 5d0eacc and v1.8.15: Close() returns nil, OnPingReceived fires, no Pong on the wire, peer Close unread.
Controls: same harness with only Data+Close, or only Close, completes cleanly.
Suggested fix
In writeFrame, keep rejecting writes after Close except for opPong:
if closeSentErr != nil {
if opcode != opPong {
return 0, net.ErrClosed
}
}
That restores the §5.5.2 Pong and lets waitCloseHandshake continue to the peer Close. Verified locally against the repro above; happy to open a PR.
Related
- #298 / #394 — outbound Ping racing
Closeon the write lock / proposal to discard inbound Ping after Close. Closed via28c6709(TestConcurrentClosePingwrite-timeout reset). That did not cover thecloseSentErr→ abort →net.ErrClosedswallow path here. - #555 — 5s pong write timeout under contention (different).
- #448 / #476 — other close/write races (fixed).
- 主要語言
- Go
- 星號
- 5.6k
- 分支
- 394
- 平均合併
- 4 天 12 小時
- 30 天內合併 PR
- 11
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
coder/websocket 的其他 Issue
-
Must not wrap io.EOF可能已有人在做 @Yanhu007 於 223 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
coder/websocket#561 · 1 個 reaction ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 3 天內回覆
-
export wstest未關閉enhancement
難度 2/5 1-3 小時 新手友好度 68/100
coder/websocket#340 · 5 則留言 · 1 個 reaction ·
維護者通常 3 天內回覆
-
難度 4/5 3-5 天 新手友好度 22/100
維護者通常 3 天內回覆
-
Read returns a truncated fragmented message as complete when the connection closes mid-message可能已有人在做 @Grivn 於 38 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 62/100
維護者通常 3 天內回覆
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 88/100
uselagoon/lagoon-cli#501 · 1 個 reaction ·
-
難度 1/5 1 小時以內 新手友好度 85/100
-
難度 1/5 1 小時以內 新手友好度 62/100
slavakurilyak/awesome-ai-agents#1026 ·
-
enhancement
難度 2/5 1-3 小時 新手友好度 70/100
Tarektouati/made#197 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100