Skip to content

Bug fixes for UDS vsock device - #495

Merged
Lencerf merged 4 commits into
google:mainfrom
Lencerf:fix/uds-vsock
Sep 13, 2026
Merged

Bug fixes for UDS vsock device#495
Lencerf merged 4 commits into
google:mainfrom
Lencerf:fix/uds-vsock

Conversation

@Lencerf

@Lencerf Lencerf commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Assisted-by: Antigravity:Claude-Opus-5

A `CONNECT <port>` line from a host client can arrive in several pieces.
For example `writeln!()` emits the literal, the port and the newline in
three separate writes. Since the accepted socket is non-blocking,
`read_line()` then fails with `EAGAIN`, and the error was propagated out
of the mio worker loop, tearing down the whole device and closing every
connection.

Keep the buffered reader and the bytes received so far in the socket map
and resume reading once the socket is readable again. Drop and
deregister the socket when the client hangs up mid-request or sends an
unparsable port.

This also fixes flaky failures of vsock_host_close_test, where the
`writeln!()` of the test itself raced with the device.

Assisted-by: Antigravity:Claude-Opus-5
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
The listener is registered with mio, which uses edge-triggered epoll,
but only one connection was accepted per event. When a client connects
while another connection is still queued, no new edge is reported and
the queued client is never served. In practice every connection was then
served one client behind: the pending connection is only accepted once
the next client connects.

Accept in a loop until `EAGAIN`. While at it, keep the device alive when
a client aborts a connection before it is accepted.

Assisted-by: Antigravity:Claude-Opus-5
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
Writing to a host socket whose client already closed fails with EPIPE.
The error was propagated out of the mio worker loop, so a single client
hanging up at the wrong moment took down the whole device together with
all other connections. Two paths are affected:

  - the "OK <port>" acknowledgement sent when the guest accepts a
    connection that the client abandoned in the meantime,
  - forwarding guest data of an established connection.

Mark the connection as EOF in both cases and let process_rx_data() send
an RST to the guest, exactly like a client that closes while idle. If
the RX queue has no descriptor at that point, flush_rx_data() delivers
the RST once the guest provides one.

Also downgrade the log for host data arriving before the guest accepts a
connection: it stays buffered in the socket and is not an error.

Assisted-by: Antigravity:Claude-Opus-5
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@coveralls

coveralls commented Sep 13, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 34744843132

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.03%) to 37.357%

Details

  • Coverage increased (+0.03%) from the base build.
  • Patch coverage: 16 uncovered changes across 1 file (84 of 100 lines covered, 84.0%).
  • 81 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
alioth/src/virtio/dev/vsock/uds_vsock.rs 100 84 84.0%

Coverage Regressions

81 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
alioth/src/virtio/dev/vsock/uds_vsock.rs 81 81.09%

Coverage Stats

Coverage Status
Relevant Lines: 15400
Covered Lines: 5579
Line Coverage: 36.23%
Relevant Branches: 1558
Covered Branches: 756
Branch Coverage: 48.52%
Branches in Coverage %: Yes
Coverage Strength: 45.7 hits per line

💛 - Coveralls

Every test repeated the same ~35 lines to set up guest memory, the
queues, the device and the worker, and then open-coded the interrupt,
descriptor and connection handshake steps.

Add a VsockTest fixture that owns the running worker, the queues and the
host socket path, with helpers for the recurring steps: offering RX
descriptors, waiting for RX messages, sending TX messages, connecting a
host client and completing the CONNECT handshake. Move the device
metadata assertions of vsock_conn_test into a separate vsock_dev_test,
as they need no worker.

No change in coverage, the file shrinks from 977 to 571 lines.

Assisted-by: Antigravity:Claude-Opus-5
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@Lencerf
Lencerf merged commit 3d5d005 into google:main Sep 13, 2026
13 checks passed
@Lencerf
Lencerf deleted the fix/uds-vsock branch September 13, 2026 07:43
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.

2 participants