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

  1. Check the cause IOException: if the connection to a network share dropped, restore connectivity and re-run.
  2. Verify no external process (backup/AV) is interfering with the file during the run.
  3. Update the transformation to the latest engine version — double-close handling has been improved in later releases.
  4. 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

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


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)