The Fix
Replaces the tcp_sockopts parameter with a socket_factory parameter in TCPConnector, allowing custom socket creation before connections.
Based on closed aio-libs/aiohttp issue #10520 · PR/commit linked
@@ -1,2 +0,0 @@
@@ -1,2 +0,0 @@
-Added ``tcp_sockopts`` to ``TCPConnector`` to allow specifying custom socket options
--- by :user:`TimMenninger`.
diff --git a/CHANGES/10520.feature.rst b/CHANGES/10520.feature.rst
Option A — Apply the official fix\nReplaces the tcp_sockopts parameter with a socket_factory parameter in TCPConnector, allowing custom socket creation before connections.\nWhen NOT to use: This fix should not be used if existing tcp_sockopts functionality is required.\n\n
Why This Fix Works in Production
- Trigger: I would like to have socket options applied before a connection is made so that they apply to handshake packets (e.g. IP_TOS, IPv6_TCLASS ).
- Mechanism: The TCPConnector did not allow custom socket options to be set before connection establishment
Why This Breaks in Prod
- The TCPConnector did not allow custom socket options to be set before connection establishment
- Production symptom (often without a traceback): I would like to have socket options applied before a connection is made so that they apply to handshake packets (e.g. IP_TOS, IPv6_TCLASS ).
Proof / Evidence
- GitHub issue: #10520
- Fix PR: https://github.com/aio-libs/aiohttp/pull/10534
- Fix commit: https://github.com/aio-libs/aiohttp/commit/3b9bb1cd5677a8c8443d16184ed36856ae105cd7
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.60
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.69
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@bdraco Should we do the same here, replacing #10474? It's not released yet, so it can still be changed.”
“I think it makes sense to use the same pattern here.”
Failure Signature (Search String)
- I would like to have socket options applied before a connection is made so that they apply to handshake packets (e.g. IP_TOS, IPv6_TCLASS ).
- The existing tcp_sockopts could be repurposed for this, however, passing in socket options like this doesn't allow one to set different options depending on the destination
Copy-friendly signature
Failure Signature
-----------------
I would like to have socket options applied before a connection is made so that they apply to handshake packets (e.g. IP_TOS, IPv6_TCLASS ).
The existing tcp_sockopts could be repurposed for this, however, passing in socket options like this doesn't allow one to set different options depending on the destination address (e.g., IPv4 vs IPv6).
Error Message
Signature-only (no traceback captured)
Error Message
-------------
I would like to have socket options applied before a connection is made so that they apply to handshake packets (e.g. IP_TOS, IPv6_TCLASS ).
The existing tcp_sockopts could be repurposed for this, however, passing in socket options like this doesn't allow one to set different options depending on the destination address (e.g., IPv4 vs IPv6).
What Broke
Users were unable to apply socket options to handshake packets, affecting connection performance.
Why It Broke
The TCPConnector did not allow custom socket options to be set before connection establishment
Fix Options (Details)
Option A — Apply the official fix
Replaces the tcp_sockopts parameter with a socket_factory parameter in TCPConnector, allowing custom socket creation before connections.
Fix reference: https://github.com/aio-libs/aiohttp/pull/10534
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if existing tcp_sockopts functionality is required.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
- Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.