Fix TCP RST data loss when closing a connection with in-flight PING frames#112
Open
anluerz wants to merge 2 commits into
Open
Fix TCP RST data loss when closing a connection with in-flight PING frames#112anluerz wants to merge 2 commits into
anluerz wants to merge 2 commits into
Conversation
30b3e9d to
b5b8683
Compare
There was a problem hiding this comment.
Pull request overview
Fixes data loss caused by TCP RST during connection shutdown when an inbound packet (e.g., a SPDY PING) arrives at a socket that still has data in the kernel send buffer. Before closing the underlying connection, shutdown now half-closes the write side and drains any inbound bytes for up to 10 seconds so the kernel emits FIN instead of RST and the peer can finish receiving in-flight data. Also fixes a minor race in Ping by reading s.pingId under pingLock.
Changes:
- In
Connection.shutdown, after all streams close, performCloseWrite+ boundedio.Copy(io.Discard, s.conn)drain befores.conn.Close(). - Move
pid := s.pingIdinside thepingLockcritical section inConnection.Ping. - Add
TestReceiveBufferIsDrainedto reproduce the truncated-transfer scenario with backpressure and concurrent pings.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| connection.go | Drain inbound bytes during graceful shutdown; tighten locking around pingId read in Ping. |
| spdy_test.go | New regression test that fills the send buffer, closes the server side, sends pings, and verifies all bytes are received. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Server closes connection while client sends periodic PING frames. A PING arriving after conn.Close() triggers RST, causing the kernel to discard the server's TCP send buffer. Signed-off-by: Andreas Erz <andreas.erz@sap.com>
Half-close with CloseWrite() and wait for Serve() to exit before calling conn.Close(), so late peer packets don't trigger RST. Also fix a pre-existing data race in Ping() where s.pingId was read outside pingLock. Signed-off-by: Andreas Erz <andreas.erz@sap.com>
b5b8683 to
ef47932
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #111