Jump to solution
Verify

The Fix

pip install redis==7.1.0

Based on closed redis/redis-py issue #1740 · PR/commit linked

Production note: This tends to surface only under concurrency. Reproduce with load tests and watch for lock contention/cancellation paths.

Jump to Verify Open PR/Commit
@@ -1276,18 +1276,17 @@ def __init__( self.ignore_subscribe_messages = ignore_subscribe_messages self.connection = None + self.subscribed_event = threading.Event() # we need to know the encoding options for this connection in order # to lookup channel and pattern names for callback handlers.
repro.py
#!/usr/bin/env python3 import threading import time import redis def poll(ps, event): print(ps.get_message(timeout=5)) event.wait() while True: message = ps.get_message(timeout=5) if message is not None: print(message) else: break def main(): r = redis.Redis.from_url("redis://localhost", health_check_interval=1) ps = r.pubsub() ps.subscribe("foo") event = threading.Event() poller = threading.Thread(target=poll, args=(ps, event)) poller.start() time.sleep(2) event.set() ps.unsubscribe("foo") poller.join() main()
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install redis==7.1.0\nWhen NOT to use: Do not use this fix if the application relies on the previous behavior of health checks with active subscriptions.\n\n

Why This Fix Works in Production

  • Trigger: redis.exceptions.ConnectionError: Bad response from PING health check because the response is b"redis-py-health-check" .
  • Mechanism: Race condition occurs when get_message is called during an unsubscribe operation, leading to misinterpretation of health check responses
  • Why the fix works: Fixes a race condition in health checks and pubsub by allowing get_message() to be called without prior subscription, preventing misinterpretation of health check responses. (first fixed release: 7.1.0).
Production impact:
  • If left unfixed, failures can be intermittent under concurrency (hard to reproduce; shows up as sporadic 5xx/timeouts).

Why This Breaks in Prod

  • Shows up under Python 3.8 in real deployments (not just unit tests).
  • Race condition occurs when get_message is called during an unsubscribe operation, leading to misinterpretation of health check responses
  • Surfaces as: redis.exceptions.ConnectionError: Bad response from PING health check\nbecause the response is b"redis-py-health-check" .

Proof / Evidence

  • GitHub issue: #1740
  • Fix PR: https://github.com/redis/redis-py/pull/1737
  • First fixed release: 7.1.0
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-07
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.61

Discussion

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

“Hey @bmerry, I ran it over 30 minutes with the fix I posted in #1737 (there's a fresh new commit), and it didn't get reproduced.…”
@barshaul · 2021-11-23 · source
“Thanks, I'll take a look when I can - but it will probably only be next week as I have some fires to put out…”
@bmerry · 2021-11-23 · source
“Using this issue I found #1737 have a different error: If UNSUBSCRIBE response is received before the PING response received: in this case get_message will…”
@barshaul · 2021-11-23 · source

Failure Signature (Search String)

  • redis.exceptions.ConnectionError: Bad response from PING health check\nbecause the response is b"redis-py-health-check" .

Error Message

Stack trace
error.txt
Error Message ------------- redis.exceptions.ConnectionError: Bad response from PING health check\nbecause the response is b"redis-py-health-check" .

Minimal Reproduction

repro.py
#!/usr/bin/env python3 import threading import time import redis def poll(ps, event): print(ps.get_message(timeout=5)) event.wait() while True: message = ps.get_message(timeout=5) if message is not None: print(message) else: break def main(): r = redis.Redis.from_url("redis://localhost", health_check_interval=1) ps = r.pubsub() ps.subscribe("foo") event = threading.Event() poller = threading.Thread(target=poll, args=(ps, event)) poller.start() time.sleep(2) event.set() ps.unsubscribe("foo") poller.join() main()

Environment

  • Python: 3.8

What Broke

This causes incorrect responses during pubsub operations, potentially leading to application errors or unexpected behavior.

Why It Broke

Race condition occurs when get_message is called during an unsubscribe operation, leading to misinterpretation of health check responses

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install redis==7.1.0

When NOT to use: Do not use this fix if the application relies on the previous behavior of health checks with active subscriptions.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/redis/redis-py/pull/1737

First fixed release: 7.1.0

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if the application relies on the previous behavior of health checks with active subscriptions.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

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

Prevention

  • Add a stress test that runs high-concurrency workloads and fails on thread dumps / blocked locks.
  • Enable watchdog dumps in prod (faulthandler, thread dump endpoint) to capture deadlocks quickly.
  • 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.

Version Compatibility Table

VersionStatus
7.1.0 Fixed

Related Issues

No related fixes found.

Sources

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