Skip to content

tcp: in incremental mode a recv waiting for a buffer no longer brings the table walk, only a look at the recvs waiting - #655

Merged
MDA2AV merged 1 commit into
mainfrom
fix/incremental-starved
Nov 23, 2026
Merged

MDA2AV merged 1 commit into
mainfrom
fix/incremental-starved

Conversation

@MDA2AV

@MDA2AV MDA2AV commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

#653 makes the sweep walk the connection table only when something needs it. One of those things is a recv parked on -ENOBUFS: the walk takes back what connections their handler let go still hold, so the recv can go on. With the shared ring any of those buffers can serve it. With a ring per connection (Incremental) none of them can, only the connection's own, and those are full because its handler has not read them. So a single upload that gets ahead of its handler brought the walk back on every tick until the handler read, and it could not help. Found in the review of #653. Main walks on every tick whatever the mode, so this was no regression.

The recv itself needs no help in the meantime: the kernel ends it with one -ENOBUFS, the data stays in the socket until TCP stops the client, and the recv is submitted again when a buffer comes back.

What changes

In incremental mode the sweep looks at the recvs that are waiting (_recvStarved), and gives back what one's handler has let go of. It makes no walk for them. That part cannot simply go: a handler that lets go of a ring it never read leaves nobody to empty it, the recv never sees the client close, and the connection keeps its descriptor. With the check left out, "a connection whose handler let go holding a dry ring is closed when its client leaves, with no read timeout" fails.

The pass that closes a condemned connection whose recv is parked still runs on every tick that used to make the walk, so at a stop with no clock set it is there as before. Shared mode is unchanged.

Per tick in incremental mode: the recvs waiting, almost always none, instead of the whole table while any is. Nothing changes per request.

Tests

In TcpSweepTests:

  • "with no clock set, a recv waiting for a buffer of the shared ring brings the walk" and "... of its own ring does not": the walk leaves a mark on a connection with a flush in progress, held there by hand.
  • "stop: with no clock set, a connection whose recv waits for a buffer its handler never gave back is let go of", which needs the pass over condemned parked recvs on the early return.

Both, with the existing incremental and let-go tests, fail on the mutants that matter: the waiting recvs given nothing back, the walk made anyway, no walk in shared mode either, the buffers of a live handler given back, and no pass over condemned parked recvs. 10 of 10 repeat runs and 3 of 3 on one core are clean.

On main with #653 and #654 merged:

Suite Result
E2E 816 passed, 0 failed, 1 skipped (a Kestrel kTLS test)
Unit 403 passed, 0 failed, 0 skipped
Http 113 passed, 0 failed, 0 skipped
File 14 passed, 0 failed, 0 skipped
Tls 217 passed, 0 failed, 41 skipped (every skip is a kTLS test: no tls module on this box)
Chaos 105 passed, 0 failed, 0 skipped
Pg, Redis not run, not reached by this change

Overlap

git merge-tree --write-tree against every open PR: this adds no conflict to #653's.

🤖 Generated with Claude Code

Base automatically changed from fix/tcp-sweep-events to main November 23, 2026 17:13
… the table walk, only a look at the recvs waiting

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.
@MDA2AV
MDA2AV force-pushed the fix/incremental-starved branch from 61a4f30 to ba055bc Compare November 23, 2026 17:14
@MDA2AV
MDA2AV merged commit 343f19f into main Nov 23, 2026
2 checks passed
@MDA2AV
MDA2AV deleted the fix/incremental-starved branch November 23, 2026 17:33
@MDA2AV MDA2AV mentioned this pull request Nov 23, 2026
MDA2AV added a commit that referenced this pull request Nov 23, 2026
All twelve csproj Version elements, 0.28.652 to 0.29.656. Carries the 3 PRs from #653 to #655. Package validation against 0.28.652, in strict mode, finds no API change in any of the eleven published packages.

Suites on this tree: Unit 403, Pg 10 (19 skipped, no server here), Redis 1 (7 skipped and 1 pending, no server here). On the same code before the bump: E2E 816 (1 kTLS skip), Http 113, Chaos 105, File 14, Tls 217 (41 kTLS skips, no tls module here).
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.

1 participant