Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The test-port reservation changes have no active review issues.
No open issues 🎉
What changed in this PR
Prevents retry tests from sending stray requests to parallel test servers by keeping the target port reserved throughout each test.
Changes:
- Adds a fixture that holds a listening port and resets incoming connections.
- Updates the retry test to use the fixture.
- Adds checks for connection resets and exclusive port ownership.
| File | Description |
|---|---|
| tests/test_apps/test_retry.py | Uses the reserved port and adds fixture regression tests. |
| tests/test_apps/conftest.py | Adds the connection-resetting listener fixture and cleanup. |
Review effort: Balanced
c9a08b4 to
9280245
Compare
test_connection_error_retried sent its GET retries to a port from unused_tcp_port, which pytest-asyncio releases before the test runs. Another pytest process running in parallel could bind that port for its own test server and count the stray request, which made tests/test_api/test_rest.py fail intermittently with an extra hit. Add a resetting_tcp_port fixture that keeps the port held by a listener for the whole test and resets every connection, so the retries still fail at the connection level and no other server can take the port. A bound socket that never listens does not work on macOS, where connects to it time out instead of being refused.
9280245 to
5cd8e76
Compare
|
Kimi review posted: #800 (review) How to ask for a Kimi review: GitHub: request @justinwlin as a reviewer, or comment |
justinwlin
left a comment
There was a problem hiding this comment.
Kimi review, round 1
Verdict: Needs changes. 0 Critical, 1 High, 2 Medium, 0 Low → not approved: both new socket tests are flaky, and required CI is red.
Next step: deanq fixes findings 2-3 with a deterministic retry test, resolves or reruns the required e2e failure, then re-requests review.
Context: The PR reserves the retry-test port with a listener that resets incoming connections.
Findings
- High: Required
e2eandvalidationchecks fail. The cold-start test polls port 8199 after flash falls back to 8200; base791cdfahas the same failure. Fix or rerun the required check before merge. - Medium: RSTs trigger an asyncio transport-setup race.
tests/test_apps/test_retry.py:158. A later retry raisesRuntimeErrorinstead ofClientConnectionError; reproduced with focused stress. Stub the connection error and assertRETRY_ATTEMPTScalls instead. - Medium: The reset assertion has a send-side race.
tests/test_apps/test_retry.py:142. An early RST makessendallraiseBrokenPipeError; reproduced in the 5,000-connection stress run. Assertrecvfirst or accept both reset outcomes.
Other reviewers, PR description, nits, what was run
- Ran: touched module → 24 passed on the first run; a rerun with global coverage disabled gave 23 passed plus one
ResourceWarningerror. Repeated new tests failed on run 9/20; focused RST stress reproduced findings 2-3, while the 100-call refused-port control passed. - Optional
test (3.14)failed during collection on OpenTelemetry deprecation warnings; the other unit jobs were cancelled. - Copilot on its PR review: Disagree; both reset-path failures reproduce at the current head. #800 (review)
To get a new review, re-request it or comment 'watcher, review'. If you push new commits, we review again by ourselves 30 minutes after the last push.
Kimi (moonshotai/Kimi-K3.1-Pro) · round 1 · 2 review agents (socket correctness, quality/PR claims/tests) · 5 min · automated review, a human owns the final call. New commits are checked every 5 min and get an automatic re-review of the changes since this round. How to ask for a Kimi review: GitHub: request @justinwlin as a reviewer, or comment @justinwlin watcher, review on the PR. Slack: DM @justin.lin Watcher, review <PR link>. New commits get an automatic re-review 30 min after the last push. Stop it: DM Watcher, stop <PR link>.
| url = f"http://127.0.0.1:{resetting_tcp_port}/run" | ||
| with patch("runpod.apps.targets.RETRY_BASE_DELAY", 0.01): | ||
| with pytest.raises(aiohttp.ClientConnectionError): | ||
| await _request_json("GET", url, {}, timeout=5) |
There was a problem hiding this comment.
Medium: Resetting during asyncio transport setup can leave the old transport registered, so a later retry raises RuntimeError: File descriptor … is used by transport instead of ClientConnectionError; reproduced with the 100-call stress test and ResourceWarning: unclosed transport. Make this a deterministic retry unit test: stub the request to raise ClientConnectionError, assert RETRY_ATTEMPTS calls, and remove the RST fixture.
| def test_resetting_port_resets_connections(resetting_tcp_port): | ||
| with socket.create_connection(("127.0.0.1", resetting_tcp_port), timeout=2) as client: | ||
| with pytest.raises(ConnectionResetError): | ||
| client.sendall(b"GET /run HTTP/1.1\r\nHost: x\r\n\r\n") |
There was a problem hiding this comment.
Medium: If the listener resets before sendall, macOS raises BrokenPipeError, so this new test flakes even though the fixture worked; reproduced in the 5,000-connection stress run. Assert recv before sending, or accept BrokenPipeError as another reset outcome.
Summary
tests/test_api/test_rest.py::test_error_body_fallbacks_do_not_mask_http_failurefails now and then withassert 2 == 1: its test server counts one more request than the test sent.The extra request comes from
tests/test_apps/test_retry.py::test_connection_error_retried. That test sends its GET retries to a port from pytest-asyncio'sunused_tcp_port, which binds a port, closes it, and returns the number. The port is free again before the test runs. When another pytest process runs at the same time (parallel worktrees, or a shared CI runner), itstest_restserver can bind that port and receive a retry. Thetest_resthandler counts every request before checking the path, so the stray GET shows up as a second hit.Change
resetting_tcp_portfixture intests/test_apps/conftest.py. A listener holds the port for the whole test, and a background thread accepts each connection and closes it withSO_LINGER 0, which sends a TCP reset. The retries still fail at the connection level (aiohttp raises aClientConnectionErrorsubclass), and no other process can bind the port while the test runs.test_connection_error_retrieduses the new fixture. It was the only user ofunused_tcp_port.A socket that is bound but never listens would be simpler, but on macOS connects to it time out instead of being refused (about 8s per attempt), so it is not used.
Only test code changes.
Tests
test_resetting_port_resets_connections: a connect to the port gets a reset quickly.test_resetting_port_cannot_be_taken_by_another_server: binding aThreadingHTTPServerto the port raisesOSError.test_restserver during the test.make quality-check: 4435 passed, 8 skipped.