{"record":{"id":"2da21141b26df141","repo":"apache/dubbo","slug":"is-not-exclusive-maybe-multiple-dubbo-instance","errorCode":null,"errorMessage":"{} is not exclusive. Maybe multiple Dubbo instances are using the same folder.","messagePattern":"(.+?) is not exclusive\\. Maybe multiple Dubbo instances are using the same folder\\.","errorType":"exception","errorClass":"PathNotExclusiveException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java","lineNumber":199,"sourceCode":"    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\n    static void removeCache(String cacheFileName) {\n        cacheMap.remove(cacheFileName);\n    }\n\n    private static class PathNotExclusiveException extends Exception {\n        public PathNotExclusiveException(String msg) {\n            super(msg);\n        }\n    }\n}\n","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java#L181-L217","documentation":"Thrown as PathNotExclusiveException by tryFileLock when dirLock is null, meaning the FileChannel.tryLock() call did not grant an exclusive lock. This happens when another JVM/Dubbo instance already holds the OS-level lock on the same cache file, or an OverlappingFileLockException was caught within the same JVM.","triggerScenarios":"Two or more Dubbo instances (or two ClassLoaders in one JVM) point at the same cache file path and both call getInstance; the second one's tryLock returns null or throws OverlappingFileLockException, so dirLock is null.","commonSituations":"Multiple application instances share a home directory or a common cache base path on a shared filesystem. Running several Dubbo processes in the same container with HOME pointing to one volume. Two webapps in one Tomcat both loading Dubbo against the same cache.","solutions":["Give each Dubbo instance its own cache base path (distinct HOME or explicit basePath) so lock files do not collide.","If sharing a filesystem is intentional, ensure only one Dubbo instance uses a given cache file at a time.","In multi-webapp containers, isolate ClassLoaders/cache paths per application.","Disable file caching (enableFileCache=false) for instances that do not need persistent cache."],"exampleFix":"// before: two instances share default ~/.dubbo\nFileCacheStoreFactory.getInstance(null, \"meta\");\n// after: per-instance path\nFileCacheStoreFactory.getInstance(\"/data/dubbo/instance-1/.dubbo\", \"meta\");","handlingStrategy":"validation","validationCode":"// Give each instance a distinct cache base path\nString basePath = \"/data/dubbo/\" + System.getProperty(\"app.id\", \"default\") + \"/.dubbo\";\nFileCacheStoreFactory.getInstance(basePath, cacheName);","typeGuard":null,"tryCatchPattern":"try {\n    FileCacheStoreFactory.getInstance(basePath, cacheName);\n} catch (Exception e) {\n    // path not exclusive; another instance owns it — use a unique path or disable cache\n    FileCacheStoreFactory.getInstance(uniqueBasePath, cacheName, false);\n}","preventionTips":["Assign each Dubbo instance its own cache base path.","Do not share a cache file across JVMs or webapps in one container.","Use enableFileCache=false for instances that do not need persistent cache.","On shared filesystems, coordinate which instance owns a given cache file."],"tags":["cache","file-lock","concurrency","multi-instance","filesystem"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}