Skip to content

fix: answer in-flight pings after sending close - #609

Open
doctorcorral wants to merge 1 commit into
coder:masterfrom
doctorcorral:fix/pong-after-close-sent
Open

doctorcorral wants to merge 1 commit into
coder:masterfrom
doctorcorral:fix/pong-after-close-sent

Conversation

@doctorcorral

Copy link
Copy Markdown

Fixes #585.

writeFrame currently rejects every opcode once closeSentErr is set. If a Ping that was already on the wire arrives during Close, handleControl tries to write a Pong, writeFrame returns net.ErrClosed, and waitCloseHandshake aborts before the peer's Close frame is read. Close then swallows net.ErrClosed and returns nil, so the caller sees success even though the handshake did not finish and no Pong was sent.

RFC 6455 §5.5.2 requires a Pong unless a Close frame has already been received. §5.5.1 only forbids further data frames after sending Close. §7.1.2 expects the endpoint to finish sending and receiving Close before tearing down TCP.

This change allows opPong through writeFrame after Close has been sent. closeReceivedErr does not need a matching check: prepareRead already stops the read loop once a Close has been received, and c.closed already refuses writes after the connection is torn down.

A net.Pipe regression test covers the case: after this side sends Close, the peer writes a Ping and then Close; we answer with a matching Pong, read the peer Close, and Close returns nil.

The same approach was previously opened as #595 and closed unmerged, without review.

This does not change WASM (ws_js.go), where the browser owns ping/pong and framing.

writeFrame refused every opcode once closeSentErr was set, so an
in-flight ping during Close aborted waitCloseHandshake before the
peer's close frame was read. RFC 6455 section 5.5.2 requires a pong
until a close frame has been received, so opPong is now allowed after
close is sent.

Fixes coder#585

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Close() aborts the closing handshake when an in-flight Ping arrives after Close is sent

1 participant