Skip to content

fix(minimald): re-establish the 8 MiB guest vsock receive window - #932

Merged
twitchyliquid64 merged 1 commit into
mainfrom
tom/session-sop
Jul 23, 2026
Merged

fix(minimald): re-establish the 8 MiB guest vsock receive window#932
twitchyliquid64 merged 1 commit into
mainfrom
tom/session-sop

Conversation

@twitchyliquid64

@twitchyliquid64 twitchyliquid64 commented Jul 23, 2026

Copy link
Copy Markdown
Member

Fixes: #886

This reverts commit 1efde29.

With libkrun/libkrun#795, we believe the guts of the ENOBUFS / file-transfer error is now well understood, with the root cause fixed by #926. This PR re-establishes a reasonable vsock buffer in the guest, without which is was almost impossible to reproduce this bug.

Note

Re-establish 8 MiB guest vsock receive window in minimald

Adds a set_vsock_rx_window helper in main.rs that sets SO_VM_SOCKETS_BUFFER_MAX_SIZE and SO_VM_SOCKETS_BUFFER_SIZE on the vsock listener socket, then reads back the effective size via getsockopt. In the vsock path of async_main, this is called immediately after binding the listener, logging the effective size or a warning if the window is smaller than requested or the call fails.

Macroscope summarized 4fd9765.

Summary by CodeRabbit

  • Improvements
    • Improved handling of large uploads by tuning the microVM listener’s receive window on Linux.
    • Added reporting when the requested window size is applied, adjusted by the system, or cannot be enabled.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Linux microVM startup now requests an 8 MiB AF_VSOCK receive window, applies the required socket options, reads back the effective size, and logs success, clamping, or failure.

Changes

AF_VSOCK receive-window tuning

Layer / File(s) Summary
Receive-window configuration
crates/minimald/src/main.rs
Defines the 8 MiB Linux receive-window target and invokes tuning after binding the vsock listener, with outcome-specific logging.
Socket option application
crates/minimald/src/main.rs
Adds a Linux helper that sets the maximum before the receive buffer size and returns the effective value from getsockopt.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • gominimal/inbox#329 — Addresses ENOBUFS in the minimald vsock upload path through a different write-side mechanism.

Possibly related PRs

Suggested reviewers: norrietaylor

Poem

I tuned the socket, eight megs wide,
So upload streams can safely glide.
The kernel tells what it could spare,
And logs the limit floating there.
Squeak! Fewer buffer woes to bear.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The change restores the guest vsock window, but it does not address the issue's primary client hang/timeout requirement. Add client-side upload timeout or deadlock handling so failed uploads surface an error instead of hanging indefinitely.
Description check ⚠️ Warning The description is relevant, but it lacks the required Summary/Testing/Checklist structure and testing evidence. Add explicit ## Summary, ## Testing, and ## Checklist sections, plus test commands/output and any docs or BREAKING CHANGE notes if needed.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changes stay focused on the vsock receive-window fix and do not introduce unrelated code paths.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is a clear conventional-commit summary and matches the main change to restore the guest vsock receive window.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@twitchyliquid64
twitchyliquid64 enabled auto-merge (squash) July 23, 2026 18:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/minimald/src/main.rs`:
- Around line 740-759: Guard the entire microVM/vsock startup branch with
#[cfg(target_os = "linux")], including the minimald::guest import and the
set_vsock_rx_window listener setup. Ensure all guest and vsock symbols remain
inside this Linux-only configuration so non-Linux builds compile when --vsock is
unused.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b2c31a26-7fdd-4b21-a706-0920bed28e50

📥 Commits

Reviewing files that changed from the base of the PR and between 1e8f271 and 4fd9765.

📒 Files selected for processing (1)
  • crates/minimald/src/main.rs

Comment on lines +740 to +759
// Widen the receive window before anything connects: `__vsock_create`
// copies `buffer_size` from the listening socket onto every socket it
// accepts, so this one call covers every session. Best effort — a
// daemon with the default window is the old, buggy behaviour, not a
// reason to refuse to boot.
match set_vsock_rx_window(&listener, VSOCK_RX_WINDOW_BYTES) {
Ok(effective) if effective >= VSOCK_RX_WINDOW_BYTES => {
tracing::debug!(bytes = effective, "raised the vsock receive window");
}
Ok(effective) => tracing::warn!(
requested = VSOCK_RX_WINDOW_BYTES,
effective,
"vsock receive window clamped below the requested size; large uploads may still \
fail with ENOBUFS"
),
Err(e) => tracing::warn!(
error = %e,
"could not raise the vsock receive window; large uploads may fail with ENOBUFS"
),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant file and the cfg-gated definitions.
git ls-files crates/minimald/src/main.rs
printf '\n--- outline: crates/minimald/src/main.rs ---\n'
ast-grep outline crates/minimald/src/main.rs --view expanded || true

printf '\n--- search for set_vsock_rx_window and VSOCK_RX_WINDOW_BYTES ---\n'
rg -n "set_vsock_rx_window|VSOCK_RX_WINDOW_BYTES|target_os = \"linux\"|vsock" crates/minimald/src/main.rs crates/minimald/src -g '!target' || true

Repository: gominimal/minimal

Length of output: 20473


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the local region around the cited lines with numbers.
sed -n '700,790p' crates/minimald/src/main.rs | cat -n

Repository: gominimal/minimal

Length of output: 4864


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- outline: crates/minimald/src/main.rs ---'
ast-grep outline crates/minimald/src/main.rs --view expanded || true

printf '\n%s\n' '--- surrounding lines 700-790 ---'
sed -n '700,790p' crates/minimald/src/main.rs | cat -n

printf '\n%s\n' '--- occurrences of relevant symbols ---'
rg -n "set_vsock_rx_window|VSOCK_RX_WINDOW_BYTES|target_os = \"linux\"|vsock" crates/minimald/src/main.rs crates/minimald/src -g '!target' || true

Repository: gominimal/minimal

Length of output: 25163


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- os-specific cfg usages in crates/minimald/src/main.rs ---'
rg -n "#\\[cfg\\(|cfg!\\(" crates/minimald/src/main.rs

printf '\n%s\n' '--- declaration search across crate ---\n'
rg -n "pub const VSOCK_RX_WINDOW_BYTES|fn set_vsock_rx_window|struct .*listener|Vsock" crates/minimald/src -g '!target' || true

Repository: gominimal/minimal

Length of output: 2506


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- lines 240-290 ---'
sed -n '240,290p' crates/minimald/src/main.rs | cat -n

printf '\n%s\n' '--- lines 620-690 ---'
sed -n '620,690p' crates/minimald/src/main.rs | cat -n

printf '\n%s\n' '--- lines 690-770 ---'
sed -n '690,770p' crates/minimald/src/main.rs | cat -n

Repository: gominimal/minimal

Length of output: 11537


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- lines 374-430 ---'
sed -n '374,430p' crates/minimald/src/main.rs | cat -n

printf '\n%s\n' '--- lines 430-520 ---'
sed -n '430,520p' crates/minimald/src/main.rs | cat -n

Repository: gominimal/minimal

Length of output: 8516


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- Cargo.toml entries for minimald ---'
rg -n "minimald|target_os|tokio_vsock|sandbox2|rustls|minimal" Cargo.toml crates/minimald/Cargo.toml . -g 'Cargo.toml' -g 'crates/minimald/Cargo.toml' || true

printf '\n%s\n' '--- crates/minimald/src/lib.rs ---'
cat -n crates/minimald/src/lib.rs

printf '\n%s\n' '--- crates/minimald/Cargo.toml (if present) ---'
if [ -f crates/minimald/Cargo.toml ]; then cat -n crates/minimald/Cargo.toml; fi

Repository: gominimal/minimal

Length of output: 12434


Guard the Linux-only microVM/vsock path.
Wrap the whole branch here, including use minimald::guest;, in #[cfg(target_os = "linux")]; otherwise non-Linux builds still fail to resolve the guest and vsock symbols even when --vsock is never used.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/minimald/src/main.rs` around lines 740 - 759, Guard the entire
microVM/vsock startup branch with #[cfg(target_os = "linux")], including the
minimald::guest import and the set_vsock_rx_window listener setup. Ensure all
guest and vsock symbols remain inside this Linux-only configuration so non-Linux
builds compile when --vsock is unused.

Source: Coding guidelines

@twitchyliquid64
twitchyliquid64 merged commit 852cee0 into main Jul 23, 2026
29 checks passed
@twitchyliquid64
twitchyliquid64 deleted the tom/session-sop branch July 23, 2026 18:56
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.

minimal: upload failure sometimes hangs the client indefinitely instead of erroring

2 participants