Skip to content

Raise the HTTP server's listen backlog to 32 - #27

Merged
ChrisCummins merged 2 commits into
recursive-oss:mainfrom
tc3oliver:fix/http-listen-backlog
Oct 27, 2026
Merged

ChrisCummins merged 2 commits into
recursive-oss:mainfrom
tc3oliver:fix/http-listen-backlog

Conversation

@tc3oliver

Copy link
Copy Markdown
Contributor

Fixes #26.

ThreadingHTTPServer listens with a backlog of 5. Connections beyond that, arriving before the accept loop takes them, are reset (macOS) or dropped (Linux) before any handler runs, so a client in a burst can get ConnectionResetError instead of a 429. This sets request_queue_size = 32.

32 leaves room for the 9 admitted requests, refused ones and /health polls, so a burst larger than the admission limit still gets a 429 rather than a reset. 16 also passed the A/B in #26; 64 is not needed. Admission (BoundedSemaphore(9)), the scheduler, 429/503 handling, cancellation and shutdown are unchanged.

Tests

  • New test_listen_backlog_holds_a_burst_of_connections: stops the accept loop and opens 16 connections. Fails on main at the 6th connect (ConnectionResetError), passes with this change.
  • A/B on main, 4 rotated rounds per value: backlog 5 failed protocol_test.py 2/4 and test_serving.py 2/4; 16, 32 and 64 failed 0/4. Details in HTTP listen backlog may cause flaky queue admission tests #26.
  • make test passes on M4 Max: engine 66 passed, 1 skipped (device-gated, same on main), smoke, packaging and protocol_test.py, which covers the 8 queued requests, the 429, cancellation and disconnect. test_serving.py covers queue capacity, disconnect, shutdown and worker failure.

Four A/B rounds and one make test do not prove the flake is gone, only that it did not recur in those runs.

ThreadingHTTPServer listens with socketserver's default backlog of 5. A
burst of connections beyond that, arriving before the accept loop takes
them, is reset on macOS and has its SYN dropped on Linux, so the client
never reaches the admission check and its 429. This made the admission
steps in protocol_test.py and test_serving.py fail intermittently.

The admission limit is unchanged.
@tc3oliver
tc3oliver marked this pull request as ready for review October 24, 2026 09:52

@ChrisCummins ChrisCummins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix. Thanks @tc3oliver!

Cheers,
Chris

@ChrisCummins
ChrisCummins enabled auto-merge (rebase) October 27, 2026 01:55
@ChrisCummins
ChrisCummins merged commit 0e3150c into recursive-oss:main Oct 27, 2026
4 checks passed
@tc3oliver
tc3oliver deleted the fix/http-listen-backlog branch November 13, 2026 05:07
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.

HTTP listen backlog may cause flaky queue admission tests

2 participants