Skip to content

fix: allow pong after close frame is sent - #602

Open
xh123637 wants to merge 1 commit into
coder:masterfrom
xh123637:fix/585-close-handshake-pong
Open

xh123637 wants to merge 1 commit into
coder:masterfrom
xh123637:fix/585-close-handshake-pong

Conversation

@xh123637

Copy link
Copy Markdown

Fixes #585

Once a close frame is sent, writeFrame refused every opcode, including pong. A ping arriving during waitCloseHandshake therefore failed its pong write, and the error aborted the drain before the peer close frame was read. Close then mapped the error to nil, so the caller saw success while no pong was sent and the peer close was never consumed.

This allows only opPong through after close is sent. RFC 6455 section 5.5.2 requires answering a ping unless a close frame was already received, and here close was sent, not received. Data frames and a second close frame are still refused, and writes after the connection is fully closed are still refused by the closed check below.

The regression test uses a raw peer over net.Pipe: it reads our close frame, sends a ping, expects a pong with the same payload, then sends its close frame. It fails before this change (no pong on the wire) and passes after.

What this does not do: it does not change the handling of pings that arrive after the peer close frame was received, and it does not touch the WASM implementation, which cannot control framing.

Tests run (Go 1.27.4):

  • go test -run TestClosePingAfterCloseSent fails before the fix (unexpected got pong: expected true but got false) and passes after, including -count=10 and -race.
  • go test ./... passes.
  • go vet ./... passes, and GOOS=js GOARCH=wasm go build ./... and go vet pass.

Not run locally: the Autobahn suite and the browser WASM tests. CI is the arbiter for those.

writeFrame refused every opcode once closeSentErr was set, so a ping arriving during waitCloseHandshake failed its pong write and aborted the drain before the peer close frame was read. Allow opPong through so RFC 6455 section 5.5.2 is honored and the handshake completes.

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