{"record":{"id":"b7fcace5d587e442","repo":"alibaba/nacos","slug":"lock-conflict","errorCode":null,"errorMessage":"lock {} conflict","messagePattern":"lock (.+?) conflict","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/com/alibaba/nacos/client/utils/ConcurrentDiskUtil.java","lineNumber":165,"sourceCode":"        } catch (InterruptedException e) {\n            LOGGER.warn(\"sleep wrong\", e);\n            // set the interrupted flag\n            Thread.currentThread().interrupt();\n        }\n    }\n    \n    private static FileLock tryLock(File file, FileChannel channel, boolean shared)\n        throws IOException {\n        FileLock result = null;\n        int i = 0;\n        do {\n            try {\n                result = channel.tryLock(0L, Long.MAX_VALUE, shared);\n            } catch (Exception e) {\n                ++i;\n                if (i > RETRY_COUNT) {\n                    LOGGER.error(\"[NA] lock \" + file.getName() + \" fail;retryed time: \" + i, e);\n                    throw new IOException(\"lock \" + file.getAbsolutePath() + \" conflict\");\n                }\n                sleep(SLEEP_BASETIME * i);\n                LOGGER.warn(\"lock \" + file.getName() + \" conflict;retry time: \" + i);\n            }\n        } while (null == result);\n        return result;\n    }\n    \n}\n","sourceCodeStart":147,"sourceCodeEnd":175,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/utils/ConcurrentDiskUtil.java#L147-L175","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"int maxLockRetries = 3;\nfor (int attempt = 0; attempt <= maxLockRetries; attempt++) {\n    try {\n        ConcurrentDiskUtil.writeFileContent(file, content, charsetName);\n        break;\n    } catch (IOException e) {\n        if (e.getMessage().contains(\"conflict\") && attempt < maxLockRetries) {\n            Thread.sleep(500L * (attempt + 1));\n            continue;\n        }\n        throw e;\n    }\n}","preventionTips":["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."],"tags":["disk","file-io","file-lock","concurrency","contention","client"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}