Python "TimeoutError" on a socket in CI
A TimeoutError (formerly socket.timeout) is raised when a socket read or connect exceeds its configured timeout. On CI runners this is frequently a transient network condition reaching an external service.
What this error means
A step or test fails with "TimeoutError: timed out" or "socket.timeout" while connecting to or reading from a remote host.
python
TimeoutError: timed outCommon causes
A slow or temporarily unreachable dependency
An external host was slow or briefly unavailable, exceeding the socket timeout.
No timeout set, then a default kicked in
A blocking socket hit a platform default timeout under load.
How to fix it
Set sane timeouts and retry transient failures
- Set an explicit, reasonable timeout on every network call.
- Wrap idempotent calls in a bounded retry with backoff.
- Fail with a clear message naming the host and timeout when retries are exhausted.
Python
import socket
sock = socket.create_connection((host, port), timeout=10)How to prevent it
- On Latchkey managed runners, self-healing infrastructure automatically retries transient network timeouts so a single blip does not fail the build.
- Always set explicit socket timeouts.
- Retry idempotent network operations with backoff.
Related guides
Python "ConnectionResetError" from a test client in CIFix "ConnectionResetError: [Errno 104] Connection reset by peer" in CI - the remote end closed a socket while…
Python "requests.exceptions.ConnectionError: Max retries exceeded" in CIFix "requests.exceptions.ConnectionError: Max retries exceeded with url" in CI - requests could not establish…
Python "httpx.ConnectError" in CIFix "httpx.ConnectError: All connection attempts failed" in CI - httpx could not open a connection to the hos…