{"record":{"id":"81a3054ba11f191a","repo":"alibaba/arthas","slug":"failed-to-create-directory-within-temp-dir-attem","errorCode":null,"errorMessage":"Failed to create directory within ${TEMP_DIR_ATTEMPTS} attempts (tried ${baseName}0 to ${baseName}${TEMP_DIR_ATTEMPTS-1})","messagePattern":"Failed to create directory within (.+?) attempts \\(tried (.+?)0 to (.+?)(.+?)\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java","lineNumber":146,"sourceCode":"        } catch (Throwable e) {\n            errorMessage = e.getMessage();\n            if (!slientInit) {\n                throw new IllegalStateException(e);\n            }\n        }\n    }\n\n    private static File createTempDir() {\n        File baseDir = new File(System.getProperty(\"java.io.tmpdir\"));\n        String baseName = \"arthas-\" + System.currentTimeMillis() + \"-\";\n\n        for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) {\n            File tempDir = new File(baseDir, baseName + counter);\n            if (tempDir.mkdir()) {\n                return tempDir;\n            }\n        }\n        throw new IllegalStateException(\"Failed to create directory within \" + TEMP_DIR_ATTEMPTS + \" attempts (tried \"\n                + baseName + \"0 to \" + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')');\n    }\n\n    public String getErrorMessage() {\n        return errorMessage;\n    }\n\n    public void setErrorMessage(String errorMessage) {\n        this.errorMessage = errorMessage;\n    }\n}\n","sourceCodeStart":128,"sourceCodeEnd":158,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/arthas-agent-attach/src/main/java/com/taobao/arthas/agent/attach/ArthasAgent.java#L128-L158","documentation":"createTempDir tries up to TEMP_DIR_ATTEMPTS (10000) mkdir() calls under java.io.tmpdir and throws this IllegalStateException if every attempt collides or fails. Arthas uses this temp dir to extract arthas-bin.zip before loading arthas-core.jar, so failure blocks the whole attach.","triggerScenarios":"java.io.tmpdir is not writable, full, or on a read-only mount; a security manager or SELinux denies mkdir; the temp partition is out of inodes/space.","commonSituations":"Container with a read-only /tmp; disk full; restrictive pod security policy; tmpdir mounted noexec/nosuid with permission issues.","solutions":["Ensure the java.io.tmpdir directory is writable and has free space/inodes.","Set -Djava.io.tmpdir=/path/to/writable/dir to a known-good location.","Relax SELinux/security-manager rules so the JVM can create directories under tmpdir."],"exampleFix":"// before\njava ... -jar arthas\n// -> Failed to create directory within 10000 attempts\n\n// after\njava -Djava.io.tmpdir=/var/tmp/arthas -jar arthas","handlingStrategy":"validation","validationCode":"java.io.File tmp = new java.io.File(System.getProperty(\"java.io.tmpdir\"));\nif (!tmp.canWrite()) throw new IllegalStateException(\"tmpdir not writable: \" + tmp);\njava.io.File probe = new java.io.File(tmp, \".arthas_probe\");\nif (!probe.mkdir()) throw new IllegalStateException(\"cannot mkdir in tmpdir\");\nprobe.delete();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set -Djava.io.tmpdir to a writable directory in containers.","Ensure free space/inodes on the temp partition.","Relax SELinux/security-manager rules for the JVM."],"tags":["arthas","filesystem","tmpdir","permissions","container"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}