Skip to content

fix: add socket timeout to iread() URL fetches - #37

Merged
petercorke merged 1 commit into
mainfrom
fix/iread-url-timeout
Aug 2, 2026
Merged

fix: add socket timeout to iread() URL fetches#37
petercorke merged 1 commit into
mainfrom
fix/iread-url-timeout

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

  • iread()'s URL-fetch path called urllib.request.urlopen(req, context=ctx) with no timeout= -- a stalled SSL handshake against a slow/unresponsive server hung indefinitely. This was hit repeatedly this session as CI flakiness: tests/base/test_io.py's test_iread/test_iread_url_handling fetch a real image from petercorke.com, and an occasional stalled handshake let pytest's own blunt --timeout=50 thread-kill fire first, surfacing as a hard failure instead of the graceful except URLError: SkipTest the tests were already written to hit.
  • Also a real production bug, not just test flakiness -- any caller of iread() on a slow URL hangs forever the same way.
  • Fix: add timeout=10 to the urlopen() call. Verified empirically that a stalled connection raises URLError wrapping TimeoutError (not some other exception type), which both iread()'s existing except clause and the tests' SkipTest path already handle correctly -- no other code changes needed.

Test plan

  • Verified the exception type empirically: a connection to a non-routable address raises urllib.error.URLError wrapping TimeoutError, confirming the existing except clause catches it.
  • tests/base/test_io.py in isolation: 125 passed in 3.7s (real network fetch succeeded well within the new budget).
  • Full suite: 771 passed, 94 skipped, no regressions.

urlopen() had no timeout, so a stalled SSL handshake against a slow
or unresponsive server hung indefinitely -- in production this means
iread() on a URL can hang forever; in CI it meant pytest's own blunt
--timeout=50 thread-kill fired first, surfacing as a hard test
failure instead of the graceful except URLError: SkipTest the test
was already written to hit. A stalled connection now raises URLError
(wrapping TimeoutError) well inside any reasonable timeout window,
which both iread()'s existing except clause and the test's SkipTest
path already handle correctly.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit 6308676 into main Aug 2, 2026
18 checks passed
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