pentaho/pentaho-kettle · warning · KettleException
Unable to close file channel for file '" + filenames[filenr…
Error message
Unable to close file channel for file '" + filenames[filenr - 1]
What it means
CsvInputData.closeFile closes the NIO file channel and the underlying FileInputStream; if closing either throws an IOException, a KettleException 'Unable to close file channel for file <name>' (note: filename comes from filenames[filenr-1], the file just processed) is thrown. The file was already read successfully; only the resource release failed.
Solutions
- Check the cause IOException: if the connection to a network share dropped, restore connectivity and re-run.
- Verify no external process (backup/AV) is interfering with the file during the run.
- Update the transformation to the latest engine version — double-close handling has been improved in later releases.
- If benign (already-closed stream), the error can often be ignored, but confirm no data loss occurred.
Defensive patterns
Strategy: try-catch
Try / catch
try { ... } catch (KettleException e) {
logError("Warning: could not close channel for '" + lastFile + "': " + e.getCause(), e);
// often benign if data was already read; verify row counts
} Prevention
- Keep network shares reachable until the transformation finishes
- Avoid double-close paths by upgrading to a fixed engine version
- Exclude data files from backup/AV handle-grabbing during runs
- Check the cause to distinguish benign already-closed from real I/O errors
When it happens
Trigger: IOException on fc.close() or fis.close() in closeFile — typically because the stream/channel was already closed, or the OS blocks the close due to an I/O error on the underlying handle.
Common situations: Files on network shares with dropped connections at end of processing; double-close after an earlier failure path; antivirus or backup software holding the file handle.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- CsvInput.Exception.CreateFieldMappingError
- e (no own message; error opening CSV file)
- Exception reading line using NIO
- throw new KettleException( e );
- A deadlock was detected between steps
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/0b7fc12f9366ae3d.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/csvinput/CsvInputData.java:270
length = 0;
}
byte[] field = new byte[length];
System.arraycopy( byteBuffer, fieldStart, field, 0, length );
return field;
}
void closeFile() throws KettleException {
try {
if ( fc != null ) {
fc.close();
}
if ( fis != null ) {
fis.close();
}
} catch ( IOException e ) {
throw new KettleException( "Unable to close file channel for file '" + filenames[filenr - 1], e );
}
}
int getStartBuffer() {
return startBuffer;
}
void setStartBuffer( int startBuffer ) {
this.startBuffer = startBuffer;
}
int getEndBuffer() {
return endBuffer;
}
boolean isCarriageReturn() {
return encodingType.isReturn( byteBuffer[endBuffer] );
}View on GitHub (pinned to f3058517a1)