xkcoding/spring-boot-demo · warning · RuntimeException

请勿重复提交

Error message

请勿重复提交

What it means

README:287 documents the same @ZooLock aspect logic as ZooLockAspect.java:77: when Curator InterProcessMutex.acquire(timeout, unit) returns false within the timeout, the aspect throws RuntimeException('请勿重复提交'). It is the README copy of the runtime duplicate-submission guard.

Source

Thrown at demo-zookeeper/README.md:287

     * @throws Throwable 异常信息
     */
    @Around("doLock()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        MethodSignature signature = (MethodSignature) point.getSignature();
        Method method = signature.getMethod();
        Object[] args = point.getArgs();
        ZooLock zooLock = method.getAnnotation(ZooLock.class);
        if (StrUtil.isBlank(zooLock.key())) {
            throw new RuntimeException("分布式锁键不能为空");
        }
        String lockKey = buildLockKey(zooLock, method, args);
        InterProcessMutex lock = new InterProcessMutex(zkClient, lockKey);
        try {
            // 假设上锁成功,以后拿到的都是 false
            if (lock.acquire(zooLock.timeout(), zooLock.timeUnit())) {
                return point.proceed();
            } else {
                throw new RuntimeException("请勿重复提交");
            }
        } finally {
            lock.release();
        }
    }

    /**
     * 构造分布式锁的键
     *
     * @param lock   注解
     * @param method 注解标记的方法
     * @param args   方法上的参数
     * @return
     * @throws NoSuchFieldException
     * @throws IllegalAccessException
     */
    private String buildLockKey(ZooLock lock, Method method, Object[] args) throws NoSuchFieldException, IllegalAccessException {
        StringBuilder key = new StringBuilder(KEY_SEPARATOR + KEY_PREFIX + lock.key());

View on GitHub (pinned to 87a142f960)

Solutions

  1. Increase the @ZooLock timeout
  2. Make the client idempotent (disable submit, idempotency token)
  3. Check ZooKeeper quorum health and session timeouts
  4. Retry with backoff where safe
Defensive patterns

Strategy: try-catch

Validate before calling

// client-side idempotency guard before calling the @ZooLock method
if (submitting) { return; }
submitting = true;
try { lockedService.doWork(req); } finally { submitting = false; }

Try / catch

try {
    lockedService.doWork(req);
} catch (RuntimeException e) {
    if ('请勿重复提交'.equals(e.getMessage())) {
        return ApiResponse.of(429, '请求处理中,请勿重复提交', null);
    }
    throw e;
}

Prevention

When it happens

Trigger: Concurrent calls to the same @ZooLock method/key; the lock holder outlasts the acquire timeout; a slow/unhealthy ZooKeeper quorum causes acquire to time out.

Common situations: Double-click submit; high concurrency on an idempotent endpoint; @ZooLock timeout too short; ZK cluster latency.

Related errors


AI-assisted analysis of xkcoding/spring-boot-demo@87a142f960 (2026-08-14). Data as JSON: /api/errors/dab898e2686c169f. Report an issue: GitHub.