{"record":{"id":"7606085362eee9d4","repo":"stanfordnlp/CoreNLP","slug":"could-not-delete-shutdown-key-file","errorCode":null,"errorMessage":"Could not delete shutdown key file","messagePattern":"Could not delete shutdown key file","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java","lineNumber":225,"sourceCode":"                k -> String.format(\"\\t\\t\\t%s = %s\", k, this.defaultProps.get(k))).collect(Collectors.joining(\"\\n\")));\n\n    this.serverExecutor = Executors.newFixedThreadPool(ArgumentParser.threads);\n    this.corenlpExecutor = Executors.newFixedThreadPool(ArgumentParser.threads);\n\n    // Generate and write a shutdown key, get optional server_id from passed in properties\n    // this way if multiple servers running can shut them all down with different ids\n    String shutdownKeyFileName;\n    if (props != null && props.getProperty(\"server_id\") != null) {\n      shutdownKeyFileName = \"corenlp.shutdown.\" + props.getProperty(\"server_id\");\n    } else {\n      shutdownKeyFileName = \"corenlp.shutdown\";\n    }\n    String tmpDir = System.getProperty(\"java.io.tmpdir\");\n    File tmpFile = new File(tmpDir + File.separator + shutdownKeyFileName);\n    tmpFile.deleteOnExit();\n    if (tmpFile.exists()) {\n      if (!tmpFile.delete()) {\n        throw new IllegalStateException(\"Could not delete shutdown key file\");\n      }\n    }\n    this.shutdownKey = new BigInteger(130, new Random()).toString(32);\n    IOUtils.writeStringToFile(shutdownKey, tmpFile.getPath(), \"utf-8\");\n    // set status port\n    if (props != null && props.containsKey(\"status_port\")) {\n      this.statusPort = Integer.parseInt(props.getProperty(\"status_port\"));\n    } else if (props != null && props.containsKey(\"port\")) {\n      this.statusPort = Integer.parseInt(props.getProperty(\"port\"));\n    }\n    // parse blockList\n    if (blockList == null) {\n      this.blockListSubnets = Collections.emptyList();\n    } else {\n      this.blockListSubnets = new ArrayList<>();\n      for (String subnet : IOUtils.readLines(blockList)) {\n        try {\n          this.blockListSubnets.add(parseSubnet(subnet));","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java#L207-L243","documentation":"On server startup StanfordCoreNLPServer writes a random shutdown key to a temp file and calls deleteOnExit(). If a file already exists at that path and File.delete() fails (e.g. locked or permission issue), an IllegalStateException is thrown and the server cannot start.","triggerScenarios":"Starting StanfordCoreNLPServer when java.io.tmpdir contains a stale shutdown-key file that cannot be deleted (read-only tmpdir, file held open by another process, Windows file locking).","commonSituations":"Multiple CoreNLP server instances running under the same user; leftover files after a crash; containers with read-only /tmp; Windows locks from a previous unclean shutdown.","solutions":["Remove the stale shutdown key file from java.io.tmpdir (file name is printed in the log at server start)","Ensure the process user has write/delete permission on java.io.tmpdir","Set -Djava.io.tmpdir to a writable directory","Kill lingering StanfordCoreNLPServer processes holding the file, then restart"],"exampleFix":"// before\njava -cp corenlp.jar edu.stanford.nlp.pipeline.StanfordCoreNLPServer  // fails on locked tmp file\n// after\njava -Djava.io.tmpdir=/var/tmp/corenlp -cp corenlp.jar edu.stanford.nlp.pipeline.StanfordCoreNLPServer","handlingStrategy":"validation","validationCode":"String tmp = System.getProperty(\"java.io.tmpdir\");\nFile dir = new File(tmp);\nif (!dir.canWrite()) throw new IllegalStateException(\"tmpdir not writable: \" + tmp);\nFile f = new File(tmp, shutdownKeyFileName);\nif (f.exists() && !f.delete()) throw new IllegalStateException(\"Stale key file locked: \" + f);","typeGuard":null,"tryCatchPattern":"try {\n  new StanfordCoreNLPServer(port, runProp, sslProp, strict, quiet, defaultProps);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"Could not delete shutdown key file\")) {\n    System.setProperty(\"java.io.tmpdir\", \"/var/tmp/corenlp\");\n    // restart server with clean tmpdir\n  } else throw e;\n}","preventionTips":["Give the server a dedicated writable tmpdir via -Djava.io.tmpdir","Run one server instance per tmpdir to avoid file contention","In Docker, mount /tmp as writable or point tmpdir at a volume"],"tags":["filesystem","startup","temp-file"],"backgroundTag":"file-delete-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}