{"record":{"id":"b342bfaa482ae0a3","repo":"apache/pulsar","slug":"cannot-create-temp-directory","errorCode":null,"errorMessage":"Cannot create temp directory","messagePattern":"Cannot create temp directory","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java","lineNumber":287,"sourceCode":"            }\n        });\n    }\n\n    private static String getPulsarDirectory(String directory) {\n        final Path directoryPath;\n        if (System.getenv(\"PULSAR_HOME\") != null) {\n            directoryPath = Path.of(System.getenv(\"PULSAR_HOME\"), directory);\n        } else {\n            directoryPath = Path.of(directory);\n        }\n        return directoryPath.toAbsolutePath().normalize().toString();\n    }\n\n    private static File createNarExtractionTempDirectory() {\n        try {\n            return Files.createTempDirectory(\"pulsar_localrunner_nars_\").toFile();\n        } catch (IOException e) {\n            throw new UncheckedIOException(\"Cannot create temp directory\", e);\n        }\n    }\n\n    @Override\n    public void close() throws Exception {\n        try {\n            stop();\n        } finally {\n            if (narExtractionDirectoryCreated != null) {\n                if (narExtractionDirectoryCreated.exists()) {\n                    FileUtils.deleteFile(narExtractionDirectoryCreated, true);\n                }\n            }\n        }\n    }\n\n    @SuppressWarnings(\"deprecation\")\n    public synchronized void stop() {","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java#L269-L305","documentation":"LocalRunner.createNarExtractionTempDirectory calls Files.createTempDirectory to make a scratch directory for extracting NAR archives. If the filesystem cannot create the directory (no writable temp dir, missing TMPDIR target, disk full), the IOException is rethrown as an UncheckedIOException with this message. It surfaces during LocalRunner startup before any function instance runs.","triggerScenarios":"Calling LocalRunner.start with an archive-based (NAR) function when java.io.tmpdir points to a non-writable, non-existent, or full directory, or when the OS temp filesystem is exhausted.","commonSituations":"Containers run with read-only /tmp, TMPDIR pointing to a deleted directory, restrictive umask/permissions on the temp path, or disk quota exhaustion on Kubernetes nodes.","solutions":["Verify the java.io.tmpdir (or TMPDIR env) points to an existing writable directory; pass -Djava.io.tmpdir=/writable/path","Free disk space or raise the quota on the volume backing temp storage","Check permissions on the temp directory (chmod/chown or run as a user with write access)","If /tmp is read-only, mount a writable emptyDir/tmpfs volume"],"exampleFix":"// before (container)\n// (no writable temp)\n// after\n// docker run -e TMPDIR=/tmp-work -v writable-vol:/tmp-work ...","handlingStrategy":"validation","validationCode":"Path tmp = Path.of(System.getProperty(\"java.io.tmpdir\", \"/tmp\"));\nif (!Files.isDirectory(tmp) || !Files.isWritable(tmp)) {\n    throw new IllegalStateException(\"Temp dir not writable: \" + tmp);\n}","typeGuard":null,"tryCatchPattern":"try {\n    runner.start(true);\n} catch (UncheckedIOException e) {\n    if (e.getMessage().contains(\"Cannot create temp directory\")) {\n        // point java.io.tmpdir to a writable location and retry\n    }\n}","preventionTips":["Ensure java.io.tmpdir/TMPDIR is writable in containers","Mount a writable emptyDir/tmpfs when /tmp is read-only","Monitor disk space on temp volumes"],"tags":["filesystem","io","startup"],"backgroundTag":"temp-directory-creation-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}