Repository navigation
tcp: the send clock runs from a flush's arm, so a tick no longer times out a flush being started by the last one's time - #654
Merged
Merged
Conversation
…s out a flush being started by the last one's time A flush is in progress from the moment it is called, and the time its deadline runs from was written only once it had armed. Off the reactor a tick can come in between: it finds a flush in progress with the last flush's time, or 0 on a connection's first, and when that is SendTimeoutMs ago it shuts a healthy connection down. The time is written right before the arm now, as the read clock's is before its claim, and the sweep times only an armed flush. Not before the in-progress flag: a call with nothing to send, or one refused as already in progress, would restart the clock of a flush that is stuck, or the read clock.
… timeout cannot stand in for it Review found no bug in the change and that nothing tested the sweep's send clock: every stall test in the suites is also ended by TCP_USER_TIMEOUT, so with the clock switched off they all still passed. SendClockTests calls the sweep on a flush in each state, and pins when the time is written: before the arm, and not by a call with nothing to send or refused behind another flush. Also from review: FlushOutstanding's comment says when the send clock applies, IFlushListener.OnParking must not throw (neither clock governs a flush left between its guard and its arm), and a fault in the E2E test's handler is reported as one.
MDA2AV
added a commit
that referenced
this pull request
Nov 23, 2026
… the table walk, only a look at the recvs waiting (#655) A recv parked on -ENOBUFS makes the sweep walk the table, to take back what connections their handler let go hold. From the shared ring any of them can end the wait. With a ring per connection only the one waiting can, and then only once its handler has let go, so the walk served nothing for as long as a handler was too busy to read an upload. The sweep now looks at the recvs waiting alone in that mode, and gives back what one's handler let go of. It cannot leave that out too: a connection whose handler lets go of a dry ring would never see its client close, and keep its descriptor. Condemned ones are let go of as before, walk or no walk. Suites, on main with #653 and #654: E2E 816 (1 kTLS skip), Unit 403, Http 113, File 14, Tls 217 (41 kTLS skips), Chaos 105, none failing.
This was referenced Nov 23, 2026
Merged
MDA2AV
added a commit
that referenced
this pull request
Nov 23, 2026
…the closing listener drops no longer outlasts the stop (#657) "stop: a datagram that reaches a socket the stop closed is dropped" failed on arm64 with "the stop ended with a handler still holding its connection", on #654 and again on #656, each time 1.26 s into the test. Its probe connects to the port until it is refused, while the stop closes the listener. A SYN that lands as the listener closes is dropped without an answer, connect waits a second for TCP to send it again, and the stop's one-second drain is over by the time the test looks for the reactor. Looping that step on main: 34 of 4,244 stops were refused after a second (1,062 ms at worst). With the probe giving up on a connect that has no answer in 100 ms: none of 4,914, 101 ms at worst.
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.
SendTimeoutMs(60 s by default) could close a healthy connection that was only just starting to send, and its client got no response.A flush is marked in progress (
_flushInProgress) as soon as it is called. The time its deadline runs from (FlushArmedMs) was written only later, once it had armed. On the reactor thread nothing can come between the two. Off it, a tick can: the sweep then finds a flush in progress with the last flush's time, or 0 on a connection's first flush, which is as old as the machine's uptime. When that is more thanSendTimeoutMsago,TcpSweepCloseshuts the connection down.It needs a handler that flushes off the reactor thread with a send timeout set, which is the default, and either a connection's first flush or one after an idle stretch longer than the timeout. The gap is usually well under a microsecond, 170-310 µs on the first flush of a process (the JIT), and longer when the flushing thread is preempted in it. Found in the review of #653 and reproduced on main:
What changes
ReadParkedMs: "before the claim, so the sweep sees both").FlushArmed). One that has been called and not armed yet is left for a later tick.It is not written before
_flushInProgress: that flag is taken by every call, so a call with nothing to send, or one refused because another flush is running, would restart the clock of a flush that is stuck, or the read clock, which reads the same time as the last one the server sent.On the flush path this is the same store, moved ahead of the compare-and-swap;
ArmFlushJITs to the same size. The sweep reads one more field, only for connections with a flush in progress. A stalled flush is still cut at the same deadline.#384 (epoxide) has the same bug. The Kotlin port (#393) does not: it posts an off-reactor flush to the reactor.
Tests
SendClockTests(Unit, new) calls the sweep on a flush in each state (called and not armed, queued, with the kernel, inside its timeout), and pins when the time is written: before the arm, and not by a call with nothing to send or refused behind another flush. No sockets and no waiting. Nine mutants, each caught by at least one of them: the time written after the arm, when the flush is called, before the nothing-staged return, or never;FlushArmedalways false, only when queued, or only when with the kernel; the sweep timing any flush that was called (main), or none.TcpTimeoutTests: "a flush a tick catches before it arms is not timed out by the last one's time" holds the in-progress flag for two send timeouts, once with no flush before it and once behind a flush that is older than the timeout, and the client must get both responses. On main's code it fails ("closed before response 1, on a flush that had not started").Before this, nothing tested the sweep's send clock.
TCP_USER_TIMEOUTends the same stalls as every other test makes, so with the clock switched off they all still passed. #653 adds a slow-reader test over a socket, which TCP_USER_TIMEOUT does not see.tlsmodule on this box)All but Unit were run on the first commit; the second changes comments and tests only.
Review
Two agents reviewed this: one the correctness of the change, one the bug's reproduction, the tests and the rest of the repo.
FlushOutstanding's comment, and "must not throw" onIFlushListener.OnParking. A listener that threw there would leave the guard taken with nothing armed, which neither clock governs; both listeners only reset a field.FlushArmedMsandReadParkedMstake the reactor's cached clock while the sweep reads a fresh one, so with a timeout below about a second a flush or read can be judged up to a tick, or a long pass, too old. And_finSentMscounts from the FIN rather than from the handler's release, so a connection that calledShutdownWriteand kept reading is gone sooner after its handler returns thanReadTimeoutMspromises.Overlap
git merge-tree --write-treeagainst every open PR: this change adds no conflict. #653 touches the same file (Reactor.Tcp.Sweep.cs) and auto-merges; the two merged passTcpTimeoutTestsand #653'sTcpSweepTests(32 of 32). #413 and #386 add lines totests/Ioxide.Tests.Unit/Program.cs, as this does, and conflict in the place they already conflict with main. The conflicts #556, #553, #413, #386 and #307 show against this branch are the ones they already have against main.🤖 Generated with Claude Code