Skip to content

Troubleshooting

Common issues and how to fix them.

Lock Acquisition Fails

Problem: Always fails to acquire

Symptoms:

  • LockAcquisitionError thrown
  • Lock never acquired

Solutions:

  1. Check if lock is stuck:
bash
redis-cli GET _lock:your:key
# If exists, check TTL
redis-cli TTL _lock:your:key
  1. Increase retry attempts:
typescript
retry: {
  maxRetries: 10,  // More retries
}
  1. Shorten TTL:
typescript
ttl: 5000,  // Shorter locks

Lock Expires Too Soon

Problem: Lock expires during operation

Symptoms:

  • lock.isHeld() returns false mid-operation
  • LockExtensionError when calling lock.extend()
  • Operation completes but lock is no longer in Redis

Solutions:

  1. Enable auto-renewal:
typescript
@WithLock({ key: 'long:{0}', autoRenew: true })
  1. Increase TTL:
typescript
ttl: 60000,  // Longer TTL

Deadlock

Problem: Circular wait for locks

Symptoms:

  • Multiple services stuck waiting
  • No progress

Solution: Always acquire locks in consistent order:

typescript
// Correct - sorted order
const [first, second] = [keyA, keyB].sort();
await lock(first);
await lock(second);

// Wrong - random order
await lock(keyA);
await lock(keyB);

Performance Issues

Problem: Lock acquisition slow

Symptoms:

  • High latency
  • Slow operations

Solutions:

  1. Check Redis latency:
bash
redis-cli --latency
  1. Reduce retry delay:
typescript
retry: {
  initialDelay: 50,  // Faster retry
}
  1. Use try-acquire for non-critical:
typescript
const lock = await this.lockService.tryAcquire(key);
if (!lock) return;  // Skip if busy

Common Errors

ErrorCauseFix
LockAcquisitionErrorCouldn't acquire lockIncrease retries or wait
LockNotOwnedErrorReleased wrong lockCheck token ownership
LockExtensionErrorLock extend failed (expired or not owned)Check TTL, enable auto-renewal

Debug Checklist

  • Redis is running
  • Plugin registered in module
  • Lock key is correct
  • TTL is appropriate
  • Auto-renewal enabled for long ops
  • Retry settings reasonable
  • No circular lock dependencies

Next Steps

Released under the MIT License.