Skip to content

Back off socket buffer sizes to the OS limit instead of failing - #13

Merged
rowan-claude merged 2 commits into
mainfrom
fix/socket-buffer-backoff
Jul 26, 2026
Merged

Back off socket buffer sizes to the OS limit instead of failing#13
rowan-claude merged 2 commits into
mainfrom
fix/socket-buffer-backoff

Conversation

@rowan-claude

Copy link
Copy Markdown
Contributor

Ports netcode 71469837 (shipped in C v1.3.5). This port still hard-failed, which is a real behaviour gap, not a cosmetic divergence.

Linux and Windows clamp an SO_SNDBUF/SO_RCVBUF request above the OS limit and return success. The BSDs reject it with ENOBUFS. OpenBSD's default sb_max is well under the 4 MB requested here, so set_send_buffer_size(4MB)? returned Err and nothing could start at all. That is precisely why the C change exists.

Semantics ported, not reinvented

Try the requested size, halve on failure, give up only once the halved size would fall below a 256 KB floor. So the smallest size ever attempted is the floor itself, and the error surfaced is the one from the last real attempt. Reduced sizes log at info, matching the C log line.

Testable without a BSD to hand

The setter is injected rather than called directly, so all three platform shapes are covered:

Shape Behaviour
Linux/Windows first attempt succeeds, nothing reduced
OpenBSD 4M and 2M rejected, 1M accepted — halving, not jumping to the floor
Hostile everything rejected, error surfaces, and every attempted size is ≥ the floor

That last assertion is the one worth having. A loop checking the floor before halving would try 128K, 64K, and eventually succeed with a uselessly small buffer on a machine that merely has a low limit — succeeding wrongly rather than failing, which is the worse outcome.

Proven able to fail: lowering the floor by one halving makes it fire, with the offending attempt list [4194304, 2097152, 1048576, 524288, 262144, 131072].

54 lib tests green.

rowan-claude and others added 2 commits July 26, 2026 13:52
Ports netcode 71469837 (shipped in C v1.3.5). This port still hard-failed, which is a
real behaviour gap and not a cosmetic divergence: Linux and Windows CLAMP an SO_SNDBUF /
SO_RCVBUF request above the OS limit and return success, but the BSDs REJECT it with
ENOBUFS. OpenBSD's default sb_max is well under the 4 MB requested here, so
`set_send_buffer_size(4MB)?` returned Err and nothing could start at all. That is why
the C change exists.

Semantics ported exactly rather than reinvented: try the requested size, halve on
failure, and give up only once the HALVED size would fall below a 256 KB floor. So the
smallest size ever attempted is the floor itself, and the error surfaced is the one from
the last real attempt. Reduced sizes are logged at info, matching the C log line.

The setter is injected rather than called directly, which is what makes this testable
without a BSD to hand:
  - Linux/Windows shape: first attempt succeeds, nothing reduced.
  - OpenBSD shape: 4M and 2M rejected, 1M accepted -- halving, not jumping to the floor.
  - Hostile shape: everything rejected, error surfaces, AND every attempted size is
    >= the floor.

That last assertion is the one worth having. A loop that checked the floor BEFORE halving
would try 128K, 64K and eventually succeed with a uselessly small buffer on a machine
that merely has a low limit -- succeeding wrongly rather than failing, which is worse.
Proven able to fail: lowering the floor by one halving makes it fire with the offending
attempt list.

54 lib tests green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
I pushed without running the project's own formatter and CI caught it -- the same class
as building under laxer flags than CI uses, which bit me twice earlier today. The
project's lint IS part of the build; running it locally is not optional politeness.

fmt --check clean, clippy clean, tests green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rowan-claude
rowan-claude merged commit 7de02b0 into main Jul 26, 2026
12 checks passed
@rowan-claude
rowan-claude deleted the fix/socket-buffer-backoff branch July 26, 2026 17:57
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