Skip to content
Latchkey

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 out

Common 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

  1. Set an explicit, reasonable timeout on every network call.
  2. Wrap idempotent calls in a bounded retry with backoff.
  3. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →