Skip to content

fixtures: raise the test server's accept backlog - #167

Open
abu-tahir-0 wants to merge 1 commit into
patsypppe:mainfrom
abu-tahir-0:fix/graybox-accept-backlog
Open

abu-tahir-0 wants to merge 1 commit into
patsypppe:mainfrom
abu-tahir-0:fix/graybox-accept-backlog

Conversation

@abu-tahir-0

Copy link
Copy Markdown

Closes #159.

Problem

test_a_correct_server_passes_every_rule_and_names_the_evidence and its neighbours fail intermittently under pytest -n auto. The failure is not the rule seeing the wrong state: the evidence subprocess dies at connect() with ConnectionResetError: [Errno 54] Connection reset by peer while the fixture server is still serving the scan's own requests, so the rule reports INDETERMINATE and the test compares that with PASS.

Root cause

The fixtures are ThreadingHTTPServer instances, and socketserver's default request_queue_size is 5. On macOS a connection is reset rather than left queued once the accept queue is full, and under xdist the server's accept loop competes with the client half of the same worker and five other workers. The reset is therefore a property of the fixture's listening socket, not of any shared rule state.

Fix

Use a ThreadingHTTPServer subclass with request_queue_size = 128 for every fixture served by server.common.serve, with a comment recording why.

Testing

  • Unpatched, pytest tests/harness/test_graybox.py -m unit -q -n auto -p no:randomly in a loop: 9/30 runs failed, all on the reset path above (different parametrisations each time).
  • With the patch, the same loop: 20/20 runs passed, plus 20 more in an earlier run.
  • ruff check / ruff format --check — clean.

Note: local runs needed NO_PROXY=localhost,127.0.0.1 because httpx 0.28 rejects this machine's NO_PROXY containing [::1]; that is unrelated to this change.

This branch has not been deployed

No deployments
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.

test: test_a_correct_server_passes_every_rule_and_names_the_evidence is flaky under pytest-xdist

1 participant