alibaba/nacos · error · IOException
lock {} conflict
Error message
lock {} conflict What it means
Thrown by ConcurrentDiskUtil.tryLock when channel.tryLock fails more than RETRY_COUNT (10) times with exponential backoff (IOException). The file lock on the target file is held by another process/thread and could not be acquired within the retry budget. The message includes the absolute path of the contended file.
Source
Thrown at client/src/main/java/com/alibaba/nacos/client/utils/ConcurrentDiskUtil.java:165
} catch (InterruptedException e) {
LOGGER.warn("sleep wrong", e);
// set the interrupted flag
Thread.currentThread().interrupt();
}
}
private static FileLock tryLock(File file, FileChannel channel, boolean shared)
throws IOException {
FileLock result = null;
int i = 0;
do {
try {
result = channel.tryLock(0L, Long.MAX_VALUE, shared);
} catch (Exception e) {
++i;
if (i > RETRY_COUNT) {
LOGGER.error("[NA] lock " + file.getName() + " fail;retryed time: " + i, e);
throw new IOException("lock " + file.getAbsolutePath() + " conflict");
}
sleep(SLEEP_BASETIME * i);
LOGGER.warn("lock " + file.getName() + " conflict;retry time: " + i);
}
} while (null == result);
return result;
}
}
View on GitHub (pinned to 9b989acdf1)
Solutions
- Reduce contention: ensure only one process/thread writes to the file at a time.
- Check for orphaned Nacos client processes that may hold locks and restart them.
- If on NFS/network filesystem, verify locking support and consider a local filesystem for cache files.
- Increase RETRY_COUNT or SLEEP_BASETIME via a custom build if contention is expected and transient.
Defensive patterns
Strategy: retry
Try / catch
int maxLockRetries = 3;
for (int attempt = 0; attempt <= maxLockRetries; attempt++) {
try {
ConcurrentDiskUtil.writeFileContent(file, content, charsetName);
break;
} catch (IOException e) {
if (e.getMessage().contains("conflict") && attempt < maxLockRetries) {
Thread.sleep(500L * (attempt + 1));
continue;
}
throw e;
}
} Prevention
- Minimize concurrent writers to the same file — serialize writes from a single thread or process.
- Check for orphaned processes holding file locks and restart them.
- Use a local filesystem instead of NFS for cache files where locking is unreliable.
- Ensure write operations are short to reduce lock-hold time.
When it happens
Trigger: Another JVM or thread holds an exclusive FileLock on the same file for longer than 10 retries with increasing sleep intervals (10ms, 20ms, ..., 100ms). On each failed attempt the method sleeps SLEEP_BASETIME * i milliseconds before retrying.
Common situations: Multiple Nacos client instances (or multiple threads in one process) writing to the same config cache file; a previous JVM crashed leaving a stale lock (rare on most OSes as locks are released on process exit); NFS or network filesystem locking issues; long-running write operations holding the lock.
Related errors
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/b7fcace5d587e442.
Report an issue: GitHub.