Skip to content

Fix file descriptor leak in CLI CSV import (CSVParser never closed)#18238

Open
PDGGK wants to merge 1 commit into
apache:masterfrom
PDGGK:fix/csv-import-fd-leak
Open

Fix file descriptor leak in CLI CSV import (CSVParser never closed)#18238
PDGGK wants to merge 1 commit into
apache:masterfrom
PDGGK:fix/csv-import-fd-leak

Conversation

@PDGGK

@PDGGK PDGGK commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Description

AbstractDataTool.readCsvFile returns a CSVParser that owns the underlying FileInputStream, but the CLI import call sites (ImportData, ImportDataTree, ImportDataTable, ImportSchemaTree) never closed it. The empty-file / invalid-header early returns leaked the file descriptor immediately, and importing a directory of many CSV files could exhaust the process limit with Too many open files.

This wraps the parser in a try-with-resources at each call site so it (and the FileInputStream it wraps) is closed on every exit path. The record Stream is fully consumed inside the block before the method returns, so closing on scope exit is safe. A test is added asserting the parser is closed after use.

This closes #18237.

readCsvFile returns a CSVParser that owns the underlying FileInputStream, but
the import call sites never closed it: early returns on an empty file or a bad
header leaked the descriptor immediately, and importing a large directory of
CSV files could exhaust file descriptors ("Too many open files"). Wrap the
parser in try-with-resources at each call site (ImportData, ImportDataTree,
ImportDataTable, ImportSchemaTree) so it and its FileInputStream are closed on
every exit; the record stream is fully consumed inside the block, so closing on
scope exit is safe. Add a test asserting the parser is closed after use.

Signed-off-by: Zihan Dai <99155080+PDGGK@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] File descriptor leak in CLI CSV import: CSVParser from readCsvFile is never closed

1 participant