Jump to solution
Details

The Fix

Modifies the WebSocketResponse.close() method to wait for a close message within its timeout window, preventing spurious abnormal closure reports.

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

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Open PR/Commit
@@ -0,0 +1 @@ @@ -0,0 +1 @@ +Fixed :py:meth:`WebSocketResponse.close() <aiohttp.web.WebSocketResponse.close>` to discard non-close messages within its timeout window after sending close -- by :user:`lenard-mosys`. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 3940c2693b7..5d5f922e6fb 100644
fix.md
Option A — Apply the official fix\nModifies the WebSocketResponse.close() method to wait for a close message within its timeout window, preventing spurious abnormal closure reports.\nWhen NOT to use: This fix should not be used if the application requires immediate closure without waiting for a close message.\n\n

Why This Fix Works in Production

  • Trigger: WebSocketResponse.close() should wait for a close frame in its timeout window
  • Mechanism: Modifies the WebSocketResponse.close() method to wait for a close message within its timeout window, preventing spurious abnormal closure reports.
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Production symptom (often without a traceback): WebSocketResponse.close() should wait for a close frame in its timeout window

Proof / Evidence

Discussion

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

“Yeah' that doesn't sound right. Feel free to make a PR, or maybe @bdraco might be interested in this one.”
@Dreamsorcerer · 2024-10-18 · source
“fixed via https://github.com/aio-libs/aiohttp/pull/9508”
@bdraco · 2024-11-21 · source

Failure Signature (Search String)

  • WebSocketResponse.close() should wait for a close frame in its timeout window
  • During the timeout wait for a close message, and discard messages that arrive before that. Only report an abnormal closure if that close message never arrives.
Copy-friendly signature
signature.txt
Failure Signature ----------------- WebSocketResponse.close() should wait for a close frame in its timeout window During the timeout wait for a close message, and discard messages that arrive before that. Only report an abnormal closure if that close message never arrives.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- WebSocketResponse.close() should wait for a close frame in its timeout window During the timeout wait for a close message, and discard messages that arrive before that. Only report an abnormal closure if that close message never arrives.

What Broke

Abnormal closure reports occur when non-close messages are received after sending a close message.

Fix Options (Details)

Option A — Apply the official fix

Modifies the WebSocketResponse.close() method to wait for a close message within its timeout window, preventing spurious abnormal closure reports.

When NOT to use: This fix should not be used if the application requires immediate closure without waiting for a close message.

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

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if the application requires immediate closure without waiting for a close message.

Did This Fix Work in Your Case?

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

Prevention

  • Make timeouts explicit and test them (unit + integration) to avoid silent behavior changes.
  • Instrument retries (attempt count + reason) and alert on spikes to catch dependency slowdowns.

Related Issues

No related fixes found.

Sources

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