Jump to solution
Details

The Fix

Significantly speeds up cookie filtering by adding a cache for morsel construction, reducing the need to create new Morsel objects for every request.

Based on closed aio-libs/aiohttp issue #9520 · PR/commit linked

Open PR/Commit
@@ -0,0 +1 @@ @@ -0,0 +1 @@ +Significantly speed up filtering cookies -- by :user:`bdraco`. diff --git a/aiohttp/cookiejar.py b/aiohttp/cookiejar.py index 9b7f38d6685..85fd7716b56 100644
fix.md
Option A — Apply the official fix\nSignificantly speeds up cookie filtering by adding a cache for morsel construction, reducing the need to create new Morsel objects for every request.\nWhen NOT to use: This fix is not applicable if using a different cookie management approach.\n\n

Why This Fix Works in Production

  • Trigger: High latency observed due to repeated cookie creation during requests.
  • Mechanism: Cookies are recreated for every request, causing performance issues
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • Shows up under Python 3.14 in real deployments (not just unit tests).
  • Cookies are recreated for every request, causing performance issues
  • Production symptom (often without a traceback): High latency observed due to repeated cookie creation during requests.

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“If we don't find another solution by the time Python 3.14 is released, we can close this one”
@bdraco · 2024-11-01 · confirmation · source
“I think its unlikely we are going to be able to improve the performance without moving away from stdlib http.cookies”
@bdraco · 2024-11-30 · confirmation · source
“<img width="1233" alt="Screenshot 2024-10-17 at 9 55 31 PM" src="https://github.com/user-attachments/assets/ca7ffb41-ad96-494f-bca3-24451cae36b8">”
@bdraco · 2024-10-21 · source
“I think we have to wait for https://github.com/python/cpython/pull/126157”
@bdraco · 2024-11-01 · source

Failure Signature (Search String)

  • High latency observed due to repeated cookie creation during requests.
Copy-friendly signature
signature.txt
Failure Signature ----------------- High latency observed due to repeated cookie creation during requests.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- High latency observed due to repeated cookie creation during requests.

Environment

  • Python: 3.14

What Broke

High latency observed due to repeated cookie creation during requests.

Why It Broke

Cookies are recreated for every request, causing performance issues

Fix Options (Details)

Option A — Apply the official fix

Significantly speeds up cookie filtering by adding a cache for morsel construction, reducing the need to create new Morsel objects for every request.

When NOT to use: This fix is not applicable if using a different cookie management approach.

Fix reference: https://github.com/aio-libs/aiohttp/pull/9204

Last verified: 2026-02-12. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if using a different cookie management approach.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.