From 6ff62b17aa1b556a1823e69ae4950f2786e0ebc1 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Sun, 2 Aug 2026 21:27:03 +1000 Subject: [PATCH] fix: add socket timeout to iread() URL fetches 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. --- src/machinevisiontoolbox/base/imageio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machinevisiontoolbox/base/imageio.py b/src/machinevisiontoolbox/base/imageio.py index de6ec9de..3649fe2a 100644 --- a/src/machinevisiontoolbox/base/imageio.py +++ b/src/machinevisiontoolbox/base/imageio.py @@ -1041,7 +1041,7 @@ def iread( headers={"User-Agent": "machinevisiontoolbox-python/1.0"}, ) try: - with urllib.request.urlopen(req, context=ctx) as resp: + with urllib.request.urlopen(req, context=ctx, timeout=10) as resp: if resp.status != 200: raise ValueError(f"HTTP {resp.status} fetching {filename}") array = np.asarray(bytearray(resp.read()), dtype="uint8")