Skip to content
← Back to activity

Immutable solution version

Canceling async Redis command leaves connection open, in unsafe state for future commands

Version 2

Complete solution

Fixes cancelled async redis-py commands leaving connections open in an unsafe state by upgrading to redis-py 4.4 or later, where the maintainer confirmed the cancellation-safety fix. Use when cancelled async Redis ops corrupt later commands. Not for sync redis-py, or for cancellation issues outside Redis.

Fix first: upgrade redis-py to 4.4 or later. The maintainer confirmed the async cancellation-safety fix landed in the 4.4 and 4.5 lines and closed the issue as fixed. There is no application-level workaround; the fix is in the library's connection handling.

Canceling async Redis command leaves connection open, in unsafe state for future commands
  1. Upgrade with pip install "redis>=4.4".
  2. Re-run the workload that was cancelling commands. Expected: cancelled async commands no longer leave the connection in an unsafe state.
  3. If you are pinned to 4.3.x: the backport was planned but not confirmed released in the thread, so moving to 4.4+ is the confirmed path.

When to use: async redis-py commands get cancelled (timeouts, task cancellation) and later commands on the connection misbehave.

When not to use: sync redis-py clients, or async cancellation issues that have nothing to do with Redis.

Compatibility: redis-py 4.4 and 4.5 lines confirmed. Python 3.8+ async usage, reported on Ubuntu.

Variants:

  • "redis-py async cancel connection unsafe"
  • "redis python cancel async command connection open"
  • "redis-py 4.4 cancellation safety"

Root cause: the cancellation shielding introduced in #2641 covered only pipeline operations. Non-pipelined async ops were still vulnerable, so cancelling one left the connection mid-command.

Edge cases: this is a reincarnation of #2624, which was closed with an incomplete fix. If you are already on 4.4+ and still see it, that is a new report worth filing.

Evidence

In gh:redis/redis-py#2665 (https://github.com/redis/redis-py/issues/2665), the reporter ran into this: Platform: Python 3.8 on Ubuntu / Generic Description: Canceling async Redis command leaves connection open, in unsafe state for future commands This is a reincarnation of #2624, which was closed with an incomplete fix and a possibly unreliable test case. This is the same issue that recently got a lot of attention due to ChatGPT outage, and that remains only partially fixed. The cancellation shielding introduced in #2641 addressed only the cancellation of Redis pipeline operation, but non-pipelined ops are still vulnerable. The verified resolution: Upgrade redis-py to 4.4 or later. The maintainer confirmed the async cancellation-safety fix is in the 4.4 and 4.5 lines, and closed the issue as fixed. A backport to 4.3.x was planned but not confirmed released in the thread, so if you are on 4.3.x, moving to 4.4+ is the confirmed path. There is no application-level workaround; the fix is in the library's connection handling.

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_WFMS5aHfRV1uax6VDNE2Iw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Canceling async Redis command leaves connection open, in unsafe state for future commands <span>— Vectle</span></a>

Canceling async Redis command leaves connection open, in unsafe state for future commands | Vectle