{"record":{"id":"e4eaed97972f51dd","repo":"binarywang/WxJava","slug":"lock-failed","errorCode":null,"errorMessage":"lock failed","messagePattern":"lock failed","errorType":"exception","errorClass":"WxRuntimeException","httpStatus":null,"severity":"error","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java","lineNumber":35,"sourceCode":" */\n@Deprecated\npublic class JedisDistributedLock implements Lock {\n  private final Pool<Jedis> jedisPool;\n  private final JedisLock lock;\n\n  public JedisDistributedLock(Pool<Jedis> jedisPool, String key){\n    this.jedisPool = jedisPool;\n    this.lock = new JedisLock(key);\n  }\n\n  @Override\n  public void lock() {\n    try (Jedis jedis = jedisPool.getResource()) {\n      if (!lock.acquire(jedis)) {\n        throw new WxRuntimeException(\"acquire timeouted\");\n      }\n    } catch (InterruptedException e) {\n      throw new WxRuntimeException(\"lock failed\", e);\n    }\n  }\n\n  @Override\n  public void lockInterruptibly() throws InterruptedException {\n    try (Jedis jedis = jedisPool.getResource()) {\n      if (!lock.acquire(jedis)) {\n        throw new WxRuntimeException(\"acquire timeouted\");\n      }\n    }\n  }\n\n  @Override\n  public boolean tryLock() {\n    try (Jedis jedis = jedisPool.getResource()) {\n      return lock.acquire(jedis);\n    } catch (InterruptedException e) {\n      throw new WxRuntimeException(\"lock failed\", e);","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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())."],"exampleFix":"// before\ndistributedLock.lock();\n// after - prefer interruptible variant for cancellable contexts\ntry {\n  distributedLock.lockInterruptibly();\n} catch (InterruptedException e) {\n  Thread.currentThread().interrupt();\n  throw new ServiceShutdownException(e);\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  distributedLock.lock();\n} catch (WxRuntimeException e) {\n  if (e.getCause() instanceof InterruptedException) {\n    Thread.currentThread().interrupt();\n    // shutdown path\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["redis","jedis","distributed-lock","concurrency","interruption"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}