发布

  • [NA] [BE] fix: prevent semaphore permits from going negative in LockService (#6688)

    frostbyte_neo 发布于 2026-05-13 11:06:48 +00:00

    bestEffortLock and executeWithLock call semaphore.setPermits(1) on every
    acquire. The Redisson 4.3.1 setPermits Lua script recomputes the limit as
    available + zcount(timeout zset) and incrby's the difference. Because the
    zset cleanup of expired permits is incremental (one entry per tryAcquire),
    the script can observe more than one entry while available is already 0,
    which makes the difference negative and drives the counter below zero.

    Symptom seen in production with multi-replica recurrent jobs using
    holdUntilExpiry=false: the permit count drops to -1 and no replica can
    acquire until the counter key TTL expires.

    Switching to trySetPermits keeps the original intent (initialize the
    counter to 1 when missing) without ever modifying an existing counter, so
    the underflow cannot occur. Recovery semantics are unchanged: tryAcquire's
    cleanup pass and the counter key TTL still heal stale state.

    下载附件