Protect QEMU vsock descriptors from repeated close - #484
Merged
Merged
Conversation
yummybomb
marked this pull request as ready for review
September 17, 2026 17:28
yummybomb
requested review from
hiroTamada
and removed request for
sjmiller609
September 17, 2026 17:57
hiroTamada
approved these changes
Sep 18, 2026
hiroTamada
left a comment
Contributor
There was a problem hiding this comment.
reviewed — descriptor ownership and deadline changes look sound. no blocking findings.
non-blocking test suggestion:
lib/hypervisor/qemu/vsock_test.go:80–87— consider ensuring the read is actually waiting before closing; currently this can pass by exercising only read-after-close.
validated locally with go test -race ./lib/hypervisor/qemu ./lib/guest and 50 repetitions of the vsock tests under the race detector. live AF_VSOCK guest behavior was not tested.
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.
Why
A failed gRPC handshake can close the same QEMU vsock connection more than once. Our wrapper closed the raw file descriptor on every call. If Linux had already reused that descriptor, the second close could close an unrelated file, including a directory being scanned during GPU cleanup.
What changed
Use
os.Fileto manage the descriptor instead of implementing reads, writes, closes, and deadlines ourselves. The socket stays nonblocking so Go's runtime poller can handle waiting and timeouts.vsockConnonly adds the vsock addresses.This protects against repeated closes and I/O racing with close. A close-once guard alone would not protect the I/O calls.
It also fixes three existing behaviors:
io.EOF, rather than an empty successful read.Testing
go test -race ./lib/hypervisor/qemu ./lib/guestpassed.bad file descriptor.Tests use local socket pairs. Not tested against a live AF_VSOCK guest connection.
Independent of #485. No dependency or generated-file changes.
Automated review summary