{"record":{"id":"ef48eb14c9a4cd12","repo":"apache/dubbo","slug":"failed-to-create-lock-file","errorCode":null,"errorMessage":"Failed to create lock file {}","messagePattern":"Failed to create lock file (.+?)","errorType":"panic","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java","lineNumber":188,"sourceCode":"            logger.warn(\n                    COMMON_CACHE_PATH_INACCESSIBLE,\n                    \"inaccessible of cache path\",\n                    \"\",\n                    \"Failed to create file store cache. Local file cache will be disabled. Cache file name: \" + name,\n                    t);\n\n            return FileCacheStore.Empty.getInstance(name);\n        }\n    }\n\n    private static void tryFileLock(FileCacheStore.Builder builder, String fileName) throws PathNotExclusiveException {\n        File lockFile = new File(fileName + \".lock\");\n\n        FileLock dirLock;\n        try {\n            lockFile.createNewFile();\n            if (!lockFile.exists()) {\n                throw new AssertionError(\"Failed to create lock file \" + lockFile);\n            }\n            FileChannel lockFileChannel = new RandomAccessFile(lockFile, \"rw\").getChannel();\n            dirLock = lockFileChannel.tryLock();\n        } catch (OverlappingFileLockException ofle) {\n            dirLock = null;\n        } catch (IOException ioe) {\n            throw new RuntimeException(ioe);\n        }\n\n        if (dirLock == null) {\n            throw new PathNotExclusiveException(\n                    fileName + \" is not exclusive. Maybe multiple Dubbo instances are using the same folder.\");\n        }\n\n        lockFile.deleteOnExit();\n        builder.directoryLock(dirLock).lockFile(lockFile);\n    }\n","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java#L170-L206","documentation":"Thrown as an AssertionError by tryFileLock when lockFile.createNewFile() either returns false or the file still does not exist afterward. The lock file is required to acquire an exclusive FileLock; if it cannot be created, the locking precondition has failed.","triggerScenarios":"FileCacheStoreFactory.tryFileLock calls lockFile.createNewFile() but the file is not creatable (e.g. a directory of the same name exists, or the parent is read-only) and the subsequent exists() check fails, triggering the assertion.","commonSituations":"Another process holds the path, the cache directory permissions changed, or a stale directory entry blocks file creation. Rare in practice because the preceding createDirectories usually catches permission issues; an AssertionError indicates an unexpected filesystem state.","solutions":["Check the cache directory for conflicting entries (a directory named <cacheName>.dubbo.cache.lock) and remove them.","Confirm the running user has write permission on the cache directory.","Retry after clearing stale .lock files when no Dubbo instance is running.","Disable file caching (enableFileCache=false) if the environment cannot support lock files."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"File lockFile = new File(cacheDir, cacheName + \".lock\");\nif (lockFile.exists() && !lockFile.isFile()) {\n    // a directory occupies the lock name; remove or rename before creating FileCacheStore\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileCacheStoreFactory.getInstance(basePath, cacheName);\n} catch (AssertionError | RuntimeException e) {\n    // lock file creation failed; clear conflicting entries or disable cache\n    FileCacheStoreFactory.getInstance(basePath, cacheName, false);\n}","preventionTips":["Keep the cache directory free of conflicting entries named like the lock file.","Confirm write permission on the cache directory.","Clear stale .lock files when no Dubbo instance is running.","Use enableFileCache=false if the environment cannot create lock files."],"tags":["cache","file-io","file-lock","filesystem","assertion"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}