Skip to content

fix: back off failing accepts and correlate responses by id - #85

Merged
yashranaway merged 1 commit into
mainfrom
t3code/transport-hardening
Aug 5, 2026
Merged

fix: back off failing accepts and correlate responses by id#85
yashranaway merged 1 commit into
mainfrom
t3code/transport-hardening

Conversation

@yashranaway

Copy link
Copy Markdown
Collaborator

Closes #15 and #18. Both are small changes to Transport.swift; separate branches would just conflict, so they travel together.

#15 — accept loop spun on failure

Every accept() error was swallowed with continue. A persistent failure — a descriptor limit is the realistic one — meant the loop ran at full speed forever while refusing every agent. Now failures back off from 50 ms to 1 s and the listener stops after 64 consecutive failures (~30 s of retries).

Stopping is the deliberate choice: a host that exits is recoverable and visible, a host that burns a core while silently refusing every connection is neither.

#18 — responses were correlated by convention only

LocalSocketClient.send never checked that the reply belonged to its request, and error paths answered with a literal "unknown" id.

The host now echoes the id as soon as it can decode one, so validation failures are correlated too — previously a rejected request lost its id even though the host had successfully parsed it. The client rejects anything else.

One deliberate exception, now named rather than incidental: CommandResponse.unknownRequestIdentifier. A host that could not read the request at all (peer rejected, unreadable frame) still has to explain why, and that reply has no id to echo. Making the check strict without it would have replaced useful errors with "mismatched response", which is worse than the bug.

Tests

A server answering with someone else's id is rejected; a sentinel reply still reaches the caller with its error code intact.

The accept backoff has no test. Reproducing a sustained accept() failure means exhausting file descriptors for the whole process, which I am not willing to do to a shared test runner for a five-line change. Saying so rather than claiming coverage I did not add.

Closes #15 and #18. Both are small changes to the same file, so they travel
together rather than conflicting as separate branches.

Accept loop: every accept() error was swallowed with continue, so a persistent
failure — a descriptor limit being the realistic one — spun the loop at full
speed forever while refusing every agent. Failures now back off from 50 ms to
1 s, and the listener stops after 64 consecutive failures. A host that exits is
recoverable; a host that burns a core while silently refusing connections is
not.

Response correlation: the client never checked that a reply belonged to its
request, and error paths answered with a literal "unknown" id. The host now
echoes the id as soon as it can decode one, so validation failures are
correlated too, and the client rejects anything else. The unknown-id sentinel
is kept and named, because a host that could not read the request at all still
has to be able to say why — that reply reaches the caller with its reason
intact.

Tested: a server answering with someone else's id is rejected, and a sentinel
reply still arrives with its error code. The accept backoff has no test —
reproducing a sustained accept failure means exhausting descriptors for the
whole process, which is not worth doing to a shared test runner.
@yashranaway
yashranaway requested a review from SarthakWade August 5, 2026 20:11
@yashranaway
yashranaway merged commit 050d52f into main Aug 5, 2026
7 checks passed
@yashranaway
yashranaway deleted the t3code/transport-hardening branch August 5, 2026 20:14
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.

A4 — Accept-loop error spin

1 participant