{"record":{"id":"0b7fc12f9366ae3d","repo":"pentaho/pentaho-kettle","slug":"unable-to-close-file-channel-for-file-filenames-filenr-1","errorCode":null,"errorMessage":"Unable to close file channel for file '\" + filenames[filenr - 1]","messagePattern":"Unable to close file channel for file '\" \\+ filenames\\[filenr - 1\\]","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"warning","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/csvinput/CsvInputData.java","lineNumber":270,"sourceCode":"      length = 0;\n    }\n\n    byte[] field = new byte[length];\n    System.arraycopy( byteBuffer, fieldStart, field, 0, length );\n\n    return field;\n  }\n\n  void closeFile() throws KettleException {\n    try {\n      if ( fc != null ) {\n        fc.close();\n      }\n      if ( fis != null ) {\n        fis.close();\n      }\n    } catch ( IOException e ) {\n      throw new KettleException( \"Unable to close file channel for file '\" + filenames[filenr - 1], e );\n    }\n  }\n\n  int getStartBuffer() {\n    return startBuffer;\n  }\n\n  void setStartBuffer( int startBuffer ) {\n    this.startBuffer = startBuffer;\n  }\n\n  int getEndBuffer() {\n    return endBuffer;\n  }\n\n  boolean isCarriageReturn() {\n    return encodingType.isReturn( byteBuffer[endBuffer] );\n  }","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/csvinput/CsvInputData.java#L252-L288","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { ... } catch (KettleException e) {\n  logError(\"Warning: could not close channel for '\" + lastFile + \"': \" + e.getCause(), e);\n  // often benign if data was already read; verify row counts\n}","preventionTips":["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"],"tags":["kettle","pentaho","resource-cleanup","io-exception"],"backgroundTag":"file-read-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}