Jump to solution
Verify

The Fix

pip install redis==7.1.0

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

Production note: Watch p95/p99 latency and retry volume; timeouts can turn into retry storms and duplicate side-effects.

Jump to Verify Open PR/Commit
@@ -249,7 +249,10 @@ def release(self) -> Awaitable[None]: expected_token = self.local.token if expected_token is None: - raise LockError("Cannot release an unlocked lock") + raise LockError( + "Cannot release a lock that's not owned or is already unlocked.",
repro.py
import redis import threading import time # Create Redis client r = redis.Redis() lock_name = "lock:example" def thread1_function(): print("Thread 1: Starting") lock = r.lock(lock_name, timeout=5) if lock.acquire(): print("Thread 1: Lock acquired") def thread2_function(): print("Thread 2: Starting") lock = r.lock(lock_name) try: lock.release() except Exception as e: print(f"Thread 2: Lock error: {e}") # Create and start threads t1 = threading.Thread(target=thread1_function) t2 = threading.Thread(target=thread2_function) t1.start() time.sleep(1) t2.start() # Wait for threads to complete t1.join() t2.join() # clean up r.delete(lock_name)
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: This fix should not be used if the lock management logic is fundamentally altered.\n\n

Why This Fix Works in Production

  • Trigger: Release a lock from a non-owned thread should raise proper error
  • Mechanism: The lock release method raises an incorrect error when called from a non-owned thread
  • Why the fix works: Fixes the LockError message when attempting to release a lock from a non-owned thread, providing a clearer error message. (first fixed release: 7.1.0).
Production impact:
  • If left unfixed, tail latency can spike under load and surface as timeouts/retries (amplifying incident impact).

Why This Breaks in Prod

  • The lock release method raises an incorrect error when called from a non-owned thread
  • Production symptom (often without a traceback): Release a lock from a non-owned thread should raise proper error

Proof / Evidence

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

Discussion

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

“Reproduce code: Output: Currently, if we release lock from thread2, we got Lock error with Lock error: Cannot release an unlocked lock, which is not true actually and will mislead the user in a way.”
Issue thread · issue description · source

Failure Signature (Search String)

  • Release a lock from a non-owned thread should raise proper error
  • lock = r.lock(lock_name, timeout=5)
Copy-friendly signature
signature.txt
Failure Signature ----------------- Release a lock from a non-owned thread should raise proper error lock = r.lock(lock_name, timeout=5)

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Release a lock from a non-owned thread should raise proper error lock = r.lock(lock_name, timeout=5)

Minimal Reproduction

repro.py
import redis import threading import time # Create Redis client r = redis.Redis() lock_name = "lock:example" def thread1_function(): print("Thread 1: Starting") lock = r.lock(lock_name, timeout=5) if lock.acquire(): print("Thread 1: Lock acquired") def thread2_function(): print("Thread 2: Starting") lock = r.lock(lock_name) try: lock.release() except Exception as e: print(f"Thread 2: Lock error: {e}") # Create and start threads t1 = threading.Thread(target=thread1_function) t2 = threading.Thread(target=thread2_function) t1.start() time.sleep(1) t2.start() # Wait for threads to complete t1.join() t2.join() # clean up r.delete(lock_name)

What Broke

Users receive misleading error messages when attempting to release locks from non-owned threads.

Why It Broke

The lock release method raises an incorrect error when called from a non-owned thread

Fix Options (Details)

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

pip install redis==7.1.0

When NOT to use: This fix should not be used if the lock management logic is fundamentally altered.

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/3534

First fixed release: 7.1.0

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 lock management logic is fundamentally altered.

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

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