Repository navigation
Bound standalone urllib responses by wall clock #1837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import importlib.util | ||
| import json | ||
| from concurrent.futures import ThreadPoolExecutor | ||
| from io import BytesIO | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
@@ -556,3 +557,16 @@ def count_home_lock(name): | |
| helper.set_active("codex", "b") | ||
| assert helper.with_accounts("codex,codex", {})["CODEX_HOME"] == str(helper.codex_home("b")) | ||
| assert home_lock_entries == [".codex-sync.lock"] * 2 | ||
|
|
||
|
|
||
| def test_provider_deadline_covers_http_error_body(helper, monkeypatch): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: ai-accounts deadline test covers only the error body and never checks that alarm state is restored The new ai-accounts test only covers an HTTPError body read that times out. It never checks that the SIGALRM handler and ITIMER_REAL are restored afterwards. It also doesn't cover the headers phase, the success-body phase, or an alarm that fires during the cleanup |
||
| request = helper.urllib.request.Request("https://example.invalid") | ||
| body = BytesIO() | ||
| monkeypatch.setattr(body, "read", lambda: helper.signal.raise_signal(helper.signal.SIGALRM)) | ||
|
|
||
| def open_(*args, **kwargs): | ||
| raise helper.urllib.error.HTTPError(request.full_url, 503, "Busy", {}, body) | ||
|
|
||
| monkeypatch.setattr(helper.urllib.request, "urlopen", open_) | ||
| with pytest.raises(TimeoutError, match="provider HTTP request timed out"): | ||
| helper._http(request, timeout=1) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: The two copies of the deadline guard check different preconditions
ai-accounts
_httprefuses to start whentimeout <= 0or a timer is already armed. Mergify_openonly checks for an armed timer. Withtimeout=0,setitimer(ITIMER_REAL, 0)disarms the timer, so the request runs without a wall-clock bound. Today the only caller uses the default of 30, so this isn't a live bug. Keeping two copies is justified because the ai-accounts script runs standalone, but they should check the same things. Add thetimeout <= 0guard to_open, or drop the parameter.