hostinet: drain recv buffer before EOF#1368
Open
russellromney wants to merge 1 commit into
Open
Conversation
A TCP peer can send data and FIN close enough together that qvisor marks the socket read side closed while bytes are already buffered. RecvMsg returned EOF from an early RClosed check before consulting the receive buffer, so the buffered bytes were never surfaced and retries kept returning EOF. Let the existing Readv path decide the result instead. It already returns buffered data before EOF and only reports EOF once the read side is closed and the buffer is empty. Add a small TCP regression client for the data-plus-FIN case.
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.
Summary
RClosed()EOF return in hostinetRecvMsgFixes #1367.
Root cause
When a peer sends data and FIN together, qvisor can process the file-read data completion and then the EOF completion before the guest application enters
recv(). The receive buffer already contains bytes, butRecvMsgcheckedbuf.RClosed()before callingReadFromBuf, so it returned clean EOF without consulting the buffer. Retrying on the same fd repeated the same early EOF shortcut.SocketBuffIntern::Readvalready has the correct ordering: copy buffered data first, then report EOF only when the buffer is empty and the read side is closed. This patch routes closed sockets through that path.Verification
On the DigitalOcean KVM repro host:
Additional fixed-Quark immediate-close image checks with the same static repro client:
Regression test binary under fixed Quark:
Build note: the repro host needed the existing local qkernel compile shims for
drivers::tee/sync_unsafe_cell, unrelated to this networking change.