consomme: remove tcp connections in closing state after timeout#3600
consomme: remove tcp connections in closing state after timeout#3600Brian-Perkins wants to merge 1 commit into
Conversation
…osed after a period of no activity
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
There was a problem hiding this comment.
Pull request overview
Implements TCP close-state cleanup in consomme so connections sitting in FinWait1/FinWait2/Closing/LastAck/TimeWait are forcibly reaped after a configurable timeout (default 60s ≈ 2·MSL per RFC 793), addressing the previous TODOs and preventing guests from leaking half-closed connections.
Changes:
- Added
ConsommeParams::tcp_close_timeout(default 60s) and renamed the localtimeoutbinding inConsomme::new_innertoudp_timeoutfor clarity. - Added
TcpConnectionInner::close_deadlinearmed on entry to any half-closed state (including on each received segment inTimeWait) and a newconnections_closed_timeoutcounter;poll_tcpreaps connections whose deadline has expired, countingTimeWaitas a normal close and the others as timeout closes. - Added four new tests in
tcp/tests.rscoveringTimeWait,FinWait1/FinWait2,Closing, andLastAckcleanup paths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| vm/devices/net/net_consomme/consomme/src/lib.rs | Adds tcp_close_timeout param with 2·MSL default; renames local timeout to udp_timeout. |
| vm/devices/net/net_consomme/consomme/src/tcp.rs | Tracks per-connection close_deadline, arms it on half-close transitions, reaps expired connections in poll_tcp, adds timeout counter. |
| vm/devices/net/net_consomme/consomme/src/tcp/tests.rs | Adds tests verifying reap and stat accounting for TimeWait, FinWait1/FinWait2, Closing, and LastAck. |
| TcpState::FinWait1 | ||
| | TcpState::FinWait2 | ||
| | TcpState::Closing | ||
| | TcpState::LastAck => self.inner.tcp.aggregate_stats.record_timeout_close(), |
There was a problem hiding this comment.
You sure about closing from these states?
I think for these states we really should be retransmitting, not terminating. And so maybe that should be saved for a separate change.
There was a problem hiding this comment.
Especially FinWait2 seems bad to terminate from--it's fine to stay in FinWait2 indefinitely, I think.
There was a problem hiding this comment.
Technically we are supposed to transmit again to make sure these state transition are seen, so it is basically a question of whether we want to make this generic, or assume a non-lossy environment. I was simplifying by assuming non-lossy.
When a socket is closed, there is a small period of time before it can be reused (per RFC 793) to make sure any old, outstanding packets are properly disposed of instead of mistakenly being given to a newly opened connection. Update the TODOs in the code to actually implement this. In addition, time out any socket that has been partially closed where the handshake is not completed by the guest. This keeps the guest from being able to leak half-closed sockets indefinitely.