{"record":{"id":"d74e9d0ee230750b","repo":"apache/flink","slug":"interrupted-when-untarring-file-infilepath","errorCode":null,"errorMessage":"Interrupted when untarring file {inFilePath}","messagePattern":"Interrupted when untarring file (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/CompressionUtils.java","lineNumber":138,"sourceCode":"    // Copy and simplify from hadoop-common package that is used in YARN\n    // See\n    // https://github.com/apache/hadoop/blob/7f93349ee74da5f35276b7535781714501ab2457/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java\n    private static void extractTarFileUsingTar(\n            String inFilePath, String targetDirPath, boolean gzipped) throws IOException {\n        inFilePath = makeSecureShellPath(inFilePath);\n        targetDirPath = makeSecureShellPath(targetDirPath);\n        String untarCommand =\n                gzipped\n                        ? String.format(\n                                \"gzip -dc '%s' | (cd '%s' && tar -xf -)\", inFilePath, targetDirPath)\n                        : String.format(\"cd '%s' && tar -xf '%s'\", targetDirPath, inFilePath);\n        Process process = new ProcessBuilder(\"bash\", \"-c\", untarCommand).start();\n        int exitCode = 0;\n        try {\n            exitCode = process.waitFor();\n        } catch (InterruptedException e) {\n            Thread.currentThread().interrupt();\n            throw new IOException(\"Interrupted when untarring file \" + inFilePath);\n        }\n        if (exitCode != 0) {\n            throw new IOException(\n                    \"Error untarring file \"\n                            + inFilePath\n                            + \". Tar process exited with exit code \"\n                            + exitCode);\n        }\n    }\n\n    // Follow the pattern suggested in\n    // https://commons.apache.org/proper/commons-compress/examples.html\n    private static void extractTarFileUsingJava(\n            String inFilePath, String targetDirPath, boolean gzipped) throws IOException {\n        try (InputStream fi = Files.newInputStream(Paths.get(inFilePath));\n                InputStream bi = new BufferedInputStream(fi);\n                final TarArchiveInputStream tai =\n                        new TarArchiveInputStream(","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/CompressionUtils.java#L120-L156","documentation":"Thrown by the Unix tar extraction path (extractTarFileUsingTar) when the thread waiting for the `bash -c \"... | tar ...\"` process is interrupted. The code restores the interrupt flag before throwing, preserving the interruption request.","triggerScenarios":"Running extractTarFile on Unix while the calling thread gets interrupted — typically a shutdown hook, task cancellation, or a test framework timeout aborting the extraction thread.","commonSituations":"Job/TaskManager shutdown racing archive extraction in a YARN container; CI test timeout interrupting a worker thread mid-extraction; explicit Future.cancel(true) on an extraction task.","solutions":["Let the interruption propagate: do not swallow it — unwind and stop the extraction work","If interruption is expected during shutdown, catch the IOException, check Thread.currentThread().isInterrupted(), and finish cleanup without starting new extractions","Avoid sharing the extracting thread with tasks that can be cancelled, or run extraction in a dedicated executor you control"],"exampleFix":"// before\nexecutor.submit(() -> CompressionUtils.extractTarFile(src, dst));\n\n// after\nFuture<?> f = executor.submit(() -> CompressionUtils.extractTarFile(src, dst));\ntry {\n    f.get(5, TimeUnit.MINUTES);\n} catch (ExecutionException e) {\n    if (Thread.interrupted()) { /* treat as shutdown, skip retry */ }\n    throw new RuntimeException(e.getCause());\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (IOException e) { if (Thread.currentThread().isInterrupted()) { abort extraction, do not retry } else { rethrow } }","preventionTips":["Run extraction in a dedicated thread/executor you never cancel mid-extraction","On shutdown paths, treat interruption as a stop signal — skip starting new extractions"],"tags":["flink-core","compression","concurrency","interruption","tar"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}