Repository navigation
Ports: a published TCP connection stays open however long it is quiet (#388) - #406
Open
sorenhoang wants to merge 1 commit into
Open
sorenhoang wants to merge 1 commit into
sorenhoang wants to merge 1 commit into
Conversation
…libracoder#388) Every relayed socket had a 300 s read timeout, so a connection with no traffic in one direction for five minutes was closed. Docker's docker-proxy and DNAT never close a quiet connection, and clients such as database pools and .NET Aspire's tunnel rely on that. The read timeout goes. Keepalive (Go's defaults, which docker-proxy runs with: 15 s idle, 15 s interval, 9 probes) now finds a peer that went away, and a direction that ends in an error shuts the other socket down both ways, so the opposite direction never waits on a quiet peer forever and the session is still freed. The 300 s write timeout stays, for a peer that takes no bytes at all.
sorenhoang
force-pushed
the
fix/388-idle-tcp-ports
branch
from
November 16, 2026 19:23
8d22233 to
30f7504
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes and why
Every socket the port relay uses (
crates/kiri/src/daemon/ports.rs) had a 300 s read timeout (TCP_IDLE). A published TCP connection with no traffic in one direction for five minutes was therefore closed: the read failed, the copy loop ended and the relay shut the connection down. Docker's docker-proxy and DNAT never close a quiet connection, and Valkey withtimeout 0, database pools on the host and .NET Aspire's tunnel rely on that, as the issue shows. The same timeout also cut a long upload to a server that sends nothing back for five minutes.relay), the NAT network (relay_tcp) and the Linux host (relay_direct).pass_on) instead of only half-closing it. Without a read deadline, the opposite direction would otherwise wait forever on a quiet peer and hold the session. A clean end of stream is still passed on as a half-close, as before.TCP_STALL), for a peer that takes no bytes at all.Fixes #388
How you tested it
The new test checks that a relayed socket has no read timeout, has the write timeout and has keepalive on with the 15 s idle time. I wrote it first and saw it fail.
Not yet tested on a running Kiri. I haven't run the issue's reproduction (
valkey/valkey:9.1published on 127.0.0.1,PINGafter 320 s of silence) before and after this change. In particular, a full shutdown waking a read blocked on the vsock stream has only been reasoned about, not observed. I'll add that output here once I have a guest build running. The Linux-only constants (TCP_KEEPIDLE,TCP_KEEPINTVL,TCP_KEEPCNT) exist in the lockedlibc0.2.191, but I couldn't cross-build the Linux host here.Tested on: macOS (Apple silicon), unit tests only
How you found it
AI tools used to write this change: yes. Claude Code helped trace the cause, write the change and the test, and draft this description; I reviewed it.
Checklist
cargo fmt,cargo clippyand the tests pass. No new clippy warnings. New code follows the file's existing formatting, since runningcargo fmtonports.rswould reformat lines this change doesn't touch.