apache/hadoop · error · IOException
Error untarring file " + inFile + ". Tar process exited with
Error message
Error untarring file " + inFile + ". Tar process exited with exit code " + exitcode + " from command " + untarCommand
What it means
unTarUsingTar builds a bash command ('bash','-c','tar -xf ... -)') and runs it via ShellCommandExecutor on non-Windows; a non-zero exit code throws IOException("Error untarring file <inFile>. Tar process exited with exit code <n> from command <cmd>"). Unlike the runCommand variant, this message includes the exact tar command, which usually reveals the cause. Common exit codes: 1/2 corrupt or truncated archive, 127 tar not found, 126 permission problem on tar.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:1080
.append(" | (");
}
untarCommand.append("cd '")
.append(FileUtil.makeSecureShellPath(untarDir))
.append("' && ")
.append("tar -xf ");
if (gzipped) {
untarCommand.append(" -)");
} else {
untarCommand.append(source);
}
LOG.debug("executing [{}]", untarCommand);
String[] shellCmd = { "bash", "-c", untarCommand.toString() };
ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd);
shexec.execute();
int exitcode = shexec.getExitCode();
if (exitcode != 0) {
throw new IOException("Error untarring file " + inFile +
". Tar process exited with exit code " + exitcode
+ " from command " + untarCommand);
}
}
static void unTarUsingJava(File inFile, File untarDir,
boolean gzipped) throws IOException {
InputStream inputStream = null;
TarArchiveInputStream tis = null;
try {
if (gzipped) {
inputStream =
new GZIPInputStream(Files.newInputStream(inFile.toPath()));
} else {
inputStream = Files.newInputStream(inFile.toPath());
}
inputStream = new BufferedInputStream(inputStream);View on GitHub (pinned to 2add963021)
Solutions
- Run the printed command manually to see tar's own stderr — it names the exact failing entry or missing binary
- Validate the archive (tar -tf / checksum) and re-download or regenerate it
- Install/point to a full GNU tar, or catch this IOException and retry with the pure-Java path: FileUtil.unTarUsingJava(inFile, untarDir, gzipped) via a manual extraction routine
- Confirm write permission on untarDir and disk space
Example fix
// before
FileUtil.unTar(inFile, untarDir);
// Error untarring file bundle.tgz. Tar process exited with exit code 2 from command ...
// after: fall back to the Java implementation when native tar fails
try {
FileUtil.unTar(inFile, untarDir);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("Tar process exited")) {
try (InputStream in = Files.newInputStream(inFile.toPath())) {
FileUtil.unTar(in, untarDir, inFile.getName().endsWith("gz"));
}
} else {
throw e;
}
} Defensive patterns
Strategy: fallback
Validate before calling
try (InputStream probe = Files.newInputStream(inFile.toPath())) {
byte[] m = new byte[2];
if (probe.read(m) == 2 && (m[0] & 0xff) == 0x1f) {
// gzip magic: unTar(File,...) infers gzipped from name only — rename or use stream API
}
} Try / catch
try {
FileUtil.unTar(inFile, untarDir);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("Tar process exited")) {
// native tar failed; retry with the pure-Java extractor
try (InputStream in = Files.newInputStream(inFile.toPath())) {
FileUtil.unTar(in, untarDir, inFile.getName().endsWith("gz"));
}
} else throw e;
} Prevention
- Run the failing printed tar command manually once — its stderr names the bad entry or missing binary
- Keep GNU tar available on extraction nodes or plan the Java fallback
- Verify archive integrity before deploying to nodes
When it happens
Trigger: unTar(File inFile, File untarDir) or unTar(stream,...) on Linux with a truncated .tar/.tgz; tar binary absent from PATH (exit 127); archive containing entries the system tar cannot create (unsupported link types, path too long); untarDir unwritable.
Common situations: Downloaded tarballs truncated by network or proxy; minimal Docker images without tar; archives created with GNU extensions failing on BusyBox tar; running as a user without write permission on the extraction dir.
Related errors
- Error executing command. %s Process exited with exit code %d
- Mkdirs failed to create " + untarDir
- expanding " + entry.getName() + " would create entry outside
- Mkdirs failed to create tar internal dir " + outputDir
- expanding " + entry.getName() + " would create file outside
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/e3846a554ba9301c.
Report an issue: GitHub.