apache/dolphinscheduler · error · IllegalMonitorStateException
Etcd lock count has gone negative for lock:
Error message
Etcd lock count has gone negative for lock:
What it means
Thrown in EtcdRegistry.releaseLock when the per-thread re-entrant lock count for the key drops below zero: the code is releasing a lock more times than it acquired it (unbalanced unlock), or the LockEntry state was corrupted. It signals a caller-side lock-protocol violation rather than an etcd failure.
Source
Thrown at dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:396
* release the lock by revoking the leaseId
*/
@Override
public boolean releaseLock(String key) {
try {
Map<String, LockEntry> lockEntryMap = threadLocalLockMap.get();
if (lockEntryMap == null) {
return true;
}
LockEntry lockEntry = lockEntryMap.get(key);
if (lockEntry == null) {
return true;
}
int newLockCount = lockEntry.lockCount.decrementAndGet();
if (newLockCount > 0) {
return true;
}
if (newLockCount < 0) {
throw new IllegalMonitorStateException("Etcd lock count has gone negative for lock: " + key);
}
client.getLeaseClient().revoke(lockEntry.leaseId);
lockEntryMap.remove(key);
if (lockEntryMap.isEmpty()) {
threadLocalLockMap.remove();
}
} catch (Exception e) {
throw new RegistryException("etcd release lock error, lockKey: " + key, e);
}
return true;
}
@Override
public void close() throws IOException {
// When the client closes, the watch also closes.
client.close();
}
View on GitHub (pinned to 02eac45a1b)
Solutions
- Audit callers to ensure every releaseLock is paired with exactly one successful acquireLock on the same thread
- Avoid releasing locks in finally blocks when acquire may have failed
- Check for double-release paths (e.g. nested try/finally both calling releaseLock)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:396 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/2a5c6d45161838c2.
Report an issue: GitHub.