Skip to content

Bug: Resource Leak in CSVHandler (Unclosed File Handles) #53

@debanshd

Description

@debanshd

In csv_handler.py, the _read_streaming and _header methods use PyArrow's pa_csv.open_csv by passing a string path. When count_rows=False (the default!), the file stream is read for schema retrieval and then abandoned without being exhausted. This can lead to file descriptor exhaustion in batch processing environments where many CSVs are analyzed sequentially without exiting the process.

Affected Location:

src/croissant_maker/handlers/csv_handler.py

    @staticmethod
    def _read_streaming(file_path: Path, convert_options, count_rows: bool = False):
        try:
            reader = pa_csv.open_csv(str(file_path), convert_options=convert_options)
        except UnicodeDecodeError as exc:
            # ...
        
        # If count_rows is False, we return without exhausting the reader!
        if count_rows:
            # exhausted
        else:
            num_rows = None # Leaves file open in memory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions