binarywang/WxJava · error · WxRuntimeException
lock failed
Error message
lock failed
What it means
Thrown by JedisDistributedLock.lock() in the catch(InterruptedException) branch. If the acquiring thread is interrupted while JedisLock.acquire() blocks, the interrupt is converted to a WxRuntimeException('lock failed') wrapping the original InterruptedException.
Source
Thrown at weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java:35
*/
@Deprecated
public class JedisDistributedLock implements Lock {
private final Pool<Jedis> jedisPool;
private final JedisLock lock;
public JedisDistributedLock(Pool<Jedis> jedisPool, String key){
this.jedisPool = jedisPool;
this.lock = new JedisLock(key);
}
@Override
public void lock() {
try (Jedis jedis = jedisPool.getResource()) {
if (!lock.acquire(jedis)) {
throw new WxRuntimeException("acquire timeouted");
}
} catch (InterruptedException e) {
throw new WxRuntimeException("lock failed", e);
}
}
@Override
public void lockInterruptibly() throws InterruptedException {
try (Jedis jedis = jedisPool.getResource()) {
if (!lock.acquire(jedis)) {
throw new WxRuntimeException("acquire timeouted");
}
}
}
@Override
public boolean tryLock() {
try (Jedis jedis = jedisPool.getResource()) {
return lock.acquire(jedis);
} catch (InterruptedException e) {
throw new WxRuntimeException("lock failed", e);View on GitHub (pinned to 1c43293a3c)
Solutions
- Avoid interrupting threads that perform blocking lock acquisition, or use tryLock(long, TimeUnit) which propagates InterruptedException.
- Catch WxRuntimeException around lock() and check getCause() instanceof InterruptedException to handle shutdown cleanly.
- Restore the interrupt status if you swallow it (Thread.currentThread().interrupt()).
Example fix
// before
distributedLock.lock();
// after - prefer interruptible variant for cancellable contexts
try {
distributedLock.lockInterruptibly();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ServiceShutdownException(e);
} Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try {
distributedLock.lock();
} catch (WxRuntimeException e) {
if (e.getCause() instanceof InterruptedException) {
Thread.currentThread().interrupt();
// shutdown path
}
throw e;
} Prevention
- Use lockInterruptibly() in cancellable contexts so you see InterruptedException directly.
- Do not interrupt threads performing blocking lock acquisition.
- Restore interrupt status if you handle the wrapped interrupt.
When it happens
Trigger: The thread executing lock() is interrupted (e.g. by application shutdown, a future cancellation, or a thread-pool eviction) while acquire() is sleeping/retrying against Redis.
Common situations: Graceful shutdown interrupting worker threads that hold pending lock acquisitions; async framework cancelling a task that was waiting on the lock; test teardown interrupting threads.
Related errors
- acquire timeouted
- unsupported method
- Parameter 'leaseMilliseconds' must grate then 0: {}
- 线程 [{}] 获取会话存档SDK失败,请检查是否已调用 closeAllSdks()
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/e4eaed97972f51dd.
Report an issue: GitHub.