Skip to content

[linux][P1] guest-init port-forward relay deadlocks under TSI: OPEN_ACK succeeds, no bytes ever reach the guest listener (scale endpoints / R17 / CRI PortForward) #446

Closed

Description

@CharlieZiChen

Environment

  • A3S Box origin/main e06137de (v3.2.6), built from source; vendored libkrun daec6e8, prebuilt libkrunfw v5.3.0
  • Host: Ubuntu, kernel 6.17.0-23-generic, x86_64, KVM, unprivileged user (no sudo involved)
  • Default TSI networking, port_map=[] (scale-owned replicas)

Summary

After #378/#379/#381 the scale relay no longer reports rejected the connection; instead every relayed connection
completes OPEN → OPEN_ACK(0) and then never delivers a single byte to the in-guest listener. ready_replicas
stays 0 forever and every GET /v1/scale/<svc> blocks 7–12 s while the API re-probes the dead endpoint.

Root cause is in src/guest/init/src/port_forward.rs: spawn_guest_reader blocks in stream.read() on a clone of the
guest TcpStream while the control loop calls stream.write_all() on the same socket for FRAME_DATA. Under the libkrun
TSI guest kernel (tsi_hijack, PF_TSI) a blocking recv() blocks a concurrent send() on the same AF_INET socket, so the
write never returns. Because the write happens while holding the streams mutex inside serve_control, the whole control
connection wedges: later OPEN frames get no ACK either. The only case that works is when the request bytes arrive in the
same read as OPEN (before the reader thread starts).

Reproduction

  1. Deterministic fixture: static C HTTP server (Content-Length response, closes after reply) in an Alpine-based OCI image.
    services.acl:
    service "web" {
      image   = "linux-http-probe:current"
      command = ["/http-fixture", "serve", "0.0.0.0", "8080"]
      ports   = ["0:8080"]
    }
  2. A3S_HOME=$(mktemp -d) a3s-box scale-api --address 127.0.0.1:19301 --state st.json --services services.acl
  3. POST /v1/scale/web desired_replicas=1, then poll GET /v1/scale/web.

Result (3/3 fresh homes): replica running, guest /proc/net/tcp shows 0.0.0.0:1F90 LISTEN,
a3s-box exec <id> -- /http-fixture get 127.0.0.1 8080 /cl returns 200 OK in 0.15 ms, but

WARN Scale replica is running but its advertised endpoint is not reachable; excluding from ready_replicas … error=timed out probing advertised endpoint http://127.0.0.1:NNNNN

repeats every 5 s; ready_replicas=0 after 150 s; curl to the live relay listener never receives a first byte.

Isolating the hop (raw frames on /tmp/a3s-box-sockets/<id>/portfwd.sock)

host writes result
OPEN(8080), wait for ACK, then DATA(GET /cl) — what local_execution/port.rs does ACK 00 in 2 ms, no DATA back (8 s timeout)
OPEN + DATA in one write() ACK, HTTP/1.1 200 OK, body, CLOSE in 1 ms
after the lost DATA, a second OPEN on the same control connection no ACK (control loop stuck)
OPEN then CLOSE guest keeps the loopback connection ESTABLISHED

strace -f on the shim shows libkrun's muxer reading the 63-byte DATA frame from the unix socket, so the frame does reach
the guest. With guest-init built at debug level, dmesg in the guest shows:

pf: serve_control received frame kind=1 stream_id=1 payload_len=2
pf: connected guest target, spawned reader stream_id=1 guest_port=8080 peer=127.0.0.1:8080
pf: guest reader thread started stream_id=1
pf: serve_control received frame kind=3 stream_id=1 payload_len=54

and nothing after it — the write_all in the FRAME_DATA arm never returns.

Minimal repro without Box code (static binary run via a3s-box exec inside a default-mode box)

connect(AF_INET); thread A: blocking recv(); main: sleep 200 ms, send() a 48-byte request.

target reader result
guest loopback 127.0.0.1:8080 blocking recv() thread send() never returns (4/4)
guest loopback sequential send→recv OK
host 127.0.0.1:18080 via TSI proxy blocking recv() thread hang
host LAN 10.1.48.28:18081 via TSI proxy blocking recv() thread hang
any of the above thread waits in poll(POLLIN) before recv() OK
host, native Linux TCP (control) blocking recv() thread OK

Expected

Bytes written by the host relay after OPEN_ACK reach the guest listener; ready_replicas reflects a working endpoint;
GET /v1/scale/<svc> does not block on data-plane probes.

Impact

  • MicroVM scale-api endpoints never become ready on Linux ([linux][P1] runtime: MicroVM TCP relay rejects all scale endpoints #370 symptom persists with a different error).
  • R17 Runtime Service host endpoints and CRI PortForward use the same guest-init relay.
  • Any guest workload that uses a blocking reader thread over a TCP socket (guest-local or outbound via TSI) hangs on its
    first concurrent send() in default networking mode — this part belongs to the vendored libkrun/libkrunfw TSI stack and
    may warrant a separate issue.

Suggested fix

In port_forward.rs, never issue a blocking recv() and a send() concurrently on one TSI socket: make the guest
target non-blocking and drive it with poll() (single relay thread per stream, or reader uses poll+MSG_DONTWAIT).
Also move the write_all out of the streams mutex so one stalled stream cannot wedge the control connection.
Regression: framed probe that sends OPEN, waits for OPEN_ACK, then sends DATA in a separate write; plus a
two-request keep-alive connection.

Relation to earlier reports

#370 (closed) described rejected the connection = OPEN_ACK(1) because unpublished listen() failed before #378.
#378 fixed the listen hop; #379/#381 stop the control plane from advertising the dead endpoint. None of them touch the
data path above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions