We hit the same issue on Microsoft-hosted ubuntu-latest agents from 20 Nov: pip install inside docker build timed out against pypi.org / files.pythonhosted.org (Read timed out and SSL: UNEXPECTED_EOF_WHILE_READING). Sharing how we narrowed it down, what we think is happening, and the workaround that unblocked us.
How we narrowed it down
- Build logs: pip retried 5x per request and gave up with
No matching distribution found. That was a symptom of the timeouts, not a missing package. - General connectivity: in the same runs, Docker Hub pulls and Debian
apt-get(300+ MB) worked fine. So the agent had internet; only PyPI was failing. - Packages: we downloaded all ~100 of our requirements (Python 3.11 / Linux wheels) from a different network without errors. So the packages and requirements were fine.
- Diagnostic step on the agent:
curlto pypi.org from the agent itself failed (TLS connect error ... unexpected eof, 60s), while acurlimages/curlcontainer on the same agent got HTTP 200 in ~0.3s. MTU was 1500 on all interfaces, which ruled out Docker networking and MTU. - Ruled out: base image (slim vs full), pip vs pip3, Dockerfile flags and pipeline config. The same failure happened in all of them.
- The clue: the failing clients (agent curl, python:3.x-slim) use OpenSSL 3.5, which offers post-quantum hybrid key exchange (
X25519MLKEM768) by default. The client that worked used an older OpenSSL without it. - A/B test in one Docker build (same agent, same image, OpenSSL 3.5.7, same package
six):- Default TLS: timed out (FAILED)
- Classic key exchange only: installed in under 1 second (OK)
Probable cause (our inference, not confirmed by Microsoft or PyPI)
- A lossy or unstable network path between Azure hosted agents and some of PyPI's Fastly CDN edges. This fits the intermittent failures and the TCP timeouts others here report, and Microsoft's event https://status.dev.azure.com/_event/912152819 reportedly points at the PyPI CDN.
- The newer post-quantum handshake makes it worse. Its first message (ClientHello) needs two network packets instead of one, so on a path that drops packets it is much more likely to stall. Some network devices also mishandle these larger handshakes. Classic key exchange fits in one packet, which would explain why it connected immediately.
Workaround (add before pip install)
RUN printf '%s\n' \
'openssl_conf = openssl_init' \
'[openssl_init]' \
'ssl_conf = ssl_sect' \
'[ssl_sect]' \
'system_default = system_default_sect' \
'[system_default_sect]' \
'Groups = X25519:P-256:P-384' \
> /etc/ssl/openssl-classic.cnf
RUN OPENSSL_CONF=/etc/ssl/openssl-classic.cnf pip install --no-cache-dir --retries 10 --timeout 60 -r requirements.txt
(Use ENV OPENSSL_CONF=... instead if you also want it for runtime HTTPS calls.)
Is it safe? Yes. Connections are still fully encrypted and certificates are still verified. X25519 / P-256 / P-384 are the standard key exchanges most HTTPS traffic used until very recently. You only give up post-quantum protection against future "record now, decrypt later" attacks, which doesn't matter for public package downloads.
Caveats
- This can't fix failures that happen before the TLS handshake (pure TCP timeouts), so keep the pip retries.
- We ran one A/B test during an intermittent issue, so this is strong evidence, not proof. Running ~20 attempts each way across a few runs would confirm whether the handshake really matters.
- Tested with pip only. uv may use a different TLS stack and ignore
OPENSSL_CONF. - Treat it as a temporary workaround until Microsoft resolves the event.