Skip to content

[linux][P2] TSI published ports (-p) deliver the server's FIN to the client exactly 5 s late #447

Closed
A3S-Lab/libkrun
#13

Description

@CharlieZiChen

Environment

  • A3S Box origin/main e06137de (v3.2.6), vendored libkrun daec6e8, libkrunfw v5.3.0; Linux 6.17, KVM, unprivileged user
  • Default TSI networking with -p <host>:<guest>

Summary

When a guest service closes a connection after replying on a published port, the host-side client receives the response
bytes within ~1 ms but the connection's EOF/FIN only arrives 5.000 s later, on every connection. Clients that need EOF to
finish (HTTP/1.0-style responses without Content-Length, Connection: close streams, ab -c N without -k, any protocol
whose framing is "server closes") pay a fixed 5 s per connection. Keep-alive and Content-Length-framed responses are
unaffected, which is why casual curl checks look fine.

Reproduction

Static C HTTP fixture in an Alpine-based OCI image (/http-fixture serve 0.0.0.0 8080), two response modes:
/cl = Content-Length + Connection: close + shutdown(SHUT_WR); /fin = no Content-Length, close terminates body.

a3s-box run -d --name n5 -p 18092:8080 linux-http-probe:current -- /http-fixture serve 0.0.0.0 8080

Three independent clients on the host, 3 fresh boxes, 26 requests total — every one:

client path first byte EOF
fixture get (raw socket, waits for EOF) /cl 0.4–4.6 ms 5000.7–5005.1 ms (10/10 per box)
fixture get /fin 0.5–2.6 ms 5000.6–5002.9 ms
curl -m 20 …/fin (needs EOF) /fin 0.6 ms time_total=5.0007 s (3/3)
python client, 20 s timeout /cl 0.5 ms eof_ms=5000.7 (3/3)
curl …/cl (Content-Length framed) /cl 0.5 ms 0.7 ms (does not wait for EOF)
curl keep-alive, 2 requests /keep — 0.8 ms / 41 ms
control: same fixture natively on the host /cl,/fin 0.1–0.6 ms 0.1–0.6 ms

The fixture logs response … keep=0 and calls shutdown(SHUT_WR)/close immediately, so the delay is not in the guest
application. Three different client timeouts (5 s, 20 s, 20 s) all see EOF at exactly 5.000 s, so it is not a client-side
timer either: the TSI host-side proxy holds the FIN for a fixed 5 s.

Earlier observed in the same form with nginx (ab -c200 -n20000 without -k stalls; with -k runs normally).

Expected

Server close()/shutdown() inside the guest propagates to the host client promptly (sub-ms on loopback), as with
bridge/passt networking and as the native control shows.

Impact

Non-keep-alive HTTP, protocols framed by server close, and load tests without keep-alive run ~5 s per connection through
-p; connection-per-request clients (many health checkers, ab, wrk without keep-alive) look like a hung service.

Notes

Likely the TSI proxy's linger/half-close handling in vendored libkrun (try_listen/host-listener path). A regression test:
publish a port, request a Connection: close response without Content-Length, assert client EOF < 1 s.

Evidence: evidence/w11/n5/trial-{1,2,3}/measurements.txt, run.log, fixture-log.txt.

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