vsock: a closed host-to-guest unix connection holds its host fd for 5 s, so bursty connections hit EMFILE
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- backend, networking
Research direction
Start with UnixProxy::release() in src/devices/src/virtio/vsock/unix.rs and follow how the muxer and reaper handle ProxyRemoval::Deferred in reaper.rs. Check how the host socket fd and proxy id are used during the five-second delay, then reproduce with the provided burst test under ulimit -n 256. Done means the fd count no longer grows by one per closed connection while late guest RSTs cannot affect a reused proxy id.
Written by the indexing model from the issue text.
Description
libkrun 1.19.8 (tag v1.19.8 built from source as a static library, and Homebrew slp/krun), macOS 27.2, Apple M5 Pro. Guest kernel 6.12.109.
What happens
A port added with krun_add_vsock_port2(ctx, port, path, true) accepts host connections on path and proxies each one to the guest. Each closed connection keeps its accepted host socket open in the VMM for about 5 seconds. Under a steady stream of short connections the fd count therefore sits at about rate × 5 s. With launchd's default soft limit of 256, the VMM reaches RLIMIT_NOFILE, accept() fails with EMFILE, and new connections are refused. virtio-fs in the same VMM fails too: rm -rf on a share reported "Directory not empty".
It is a hold, not a leak. Three bursts of 200 sequential connections (connect, read one byte, close), then lsof -p <vmm> | wc -l every 0.5 s:
| fds | |
|---|---|
| baseline | 105 |
| after burst 1 (200 connections in 3.4 s) | 305 |
| after burst 2 (4.5 s later) | 358 |
| after burst 3 (2.2 s later) | 467 |
| 0.5 s after the last connection | 467 |
| 1.1 s | 318 |
| 3.1 s | 184 |
| 5.1 s and after | 104 |
The count climbs by one fd per connection. It plateaus once connections start aging past 5 s, and it returns to baseline in steps, 5 s after the last connection.
Why
UnixProxy::release() returns ProxyRemoval::Deferred for every connection that reached Connected (src/devices/src/virtio/vsock/unix.rs). The muxer hands it to the reaper, which removes the proxy after TIMEOUT = 5 s (reaper.rs), and only then drops its OwnedFd. The host socket is shut down at release, but its descriptor lives on for the full deferral.
Reproduce
Guest, as the workload (python3 has AF_VSOCK):
import socket
s = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
s.bind((socket.VMADDR_CID_ANY, 1025)); s.listen(512)
while True:
c, _ = s.accept()
try: c.sendall(b"x")
except OSError: pass
c.close()
Host launcher (C, links libkrun):
krun_add_vsock_port2(ctx, 1025, "/tmp/krun-a30.sock", true);
Host driver:
pid=<vmm pid>
for burst in 1 2 3; do
for i in $(seq 200); do nc -U /tmp/krun-a30.sock </dev/null >/dev/null; done
echo "after burst $burst: $(lsof -p $pid | wc -l)"
done
for i in $(seq 12); do sleep 0.5; echo "idle: $(lsof -p $pid | wc -l)"; done
Run the VMM with ulimit -n 256 to see EMFILE.
Ask
One of:
- On release from
Connected, close the host fd right away. Keep only the proxy id reserved for the 5 s, which is what the deferral is for: a late RST from the guest must not hit a reused id. The fd isn't needed for that. - Or document the 5 s hold next to
krun_add_vsock_port2, so embedders know to raiseRLIMIT_NOFILEor to multiplex one long-lived connection.
Also seen
In the same runs, about 1 in 200 host connections got no data from the guest within 2 s; the rest completed in under 20 ms. We haven't isolated this yet, and it may be worth its own issue.
What we did meanwhile
We raised RLIMIT_NOFILE to 65536 in the VMM and carry every exec on one long-lived, multiplexed, guest-initiated connection.
- Dominant language
- Rust
- Stars
- 2.8k
- Forks
- 279
- Avg merge
- 5d 19h
- Merged PRs (30d)
- 48
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from libkrun/libkrun
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
libkrun/libkrun#895 · 2 comments ·
Maintainers usually reply within 3 days
-
virtio/fs/windows: the owner, mode and xattrs of a symlink are read and written on its target (CVE-2026-135101)Possibly taken @nuri-yoo claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 20/100
Maintainers usually reply within 3 days
-
virtio/fs/windows: rename and link act on another entry when a name ends in a dot or a space (CVE-2026-135102)Possibly taken @nuri-yoo claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Maintainers usually reply within 3 days
-
Difficulty 4/5 1-2 days Newbie friendliness 52/100
Maintainers usually reply within 3 days
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
marketing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
difficulty: easy docs help wanted tooling
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
bug help wanted ui
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
userFRM/egui-charts#4386 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
eliasstravik/herdr-projects#1605 · 1 comment ·