Jump to solution
Verify

The Fix

Fixes the health check handling in the PubSub client to ensure consistent responses based on the decode_responses setting.

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

Jump to Verify Open PR/Commit
@@ -1009,10 +1009,22 @@ def is_health_check_response(self, response) -> bool: bulk response, instead of a multi-bulk with "pong" and the response. """ - return response in [ - self.health_check_response, # If there was a subscription - self.health_check_response_b, # If there wasn't
repro.py
File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 1016, in punsubscribe return self.execute_command("PUNSUBSCRIBE", *args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 874, in execute_command self.clean_health_check_responses() File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 890, in clean_health_check_responses raise PubSubError( redis.exceptions.PubSubError: A non health check response was cleaned by execute_command: redis-py-health-check
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Apply the official fix\nFixes the health check handling in the PubSub client to ensure consistent responses based on the decode_responses setting.\nWhen NOT to use: This fix should not be applied if the application relies on the previous inconsistent behavior.\n\n

Why This Fix Works in Production

  • Trigger: return self.execute_command("PUNSUBSCRIBE", *args)
  • Mechanism: Inconsistent handling of health check responses in the PubSub client based on decode_responses setting
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.12 in real deployments (not just unit tests).
  • Inconsistent handling of health check responses in the PubSub client based on decode_responses setting
  • Surfaces as: File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 1016, in punsubscribe

Proof / Evidence

Discussion

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

“Hi @ManelCoutinhoSensei, thank you for reporting this! We will have a look at it.”
@petyaslavova · 2025-10-08 · source
“@petyaslavova would it make you life easier if opened a PR with just this change and then you only have to think about it/review it”
@ManelCoutinhoSensei · 2025-11-06 · source

Failure Signature (Search String)

  • return self.execute_command("PUNSUBSCRIBE", *args)

Error Message

Stack trace
error.txt
Error Message ------------- File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 1016, in punsubscribe return self.execute_command("PUNSUBSCRIBE", *args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 874, in execute_command self.clean_health_check_responses() File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 890, in clean_health_check_responses raise PubSubError( redis.exceptions.PubSubError: A non health check response was cleaned by execute_command: redis-py-health-check

Minimal Reproduction

repro.py
File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 1016, in punsubscribe return self.execute_command("PUNSUBSCRIBE", *args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 874, in execute_command self.clean_health_check_responses() File "/usr/local/lib/python3.12/dist-packages/redis/client.py", line 890, in clean_health_check_responses raise PubSubError( redis.exceptions.PubSubError: A non health check response was cleaned by execute_command: redis-py-health-check

Environment

  • Python: 3.12

What Broke

Encountered PubSubError during health check response handling, causing application errors.

Why It Broke

Inconsistent handling of health check responses in the PubSub client based on decode_responses setting

Fix Options (Details)

Option A — Apply the official fix

Fixes the health check handling in the PubSub client to ensure consistent responses based on the decode_responses setting.

When NOT to use: This fix should not be applied if the application relies on the previous inconsistent behavior.

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

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 should not be applied if the application relies on the previous inconsistent behavior.

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

  • 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.