Skip to content

Conversation

ebyhr
Copy link
Contributor

@ebyhr ebyhr commented Oct 14, 2025

When avro file is malformed, DataFileReader.openReader can exit by throwing InvalidAvroMagicException which will leave input stream open and in the result, leaked.

Supersedes #13409

@github-actions github-actions bot added the core label Oct 14, 2025
Copy link
Contributor

@singhpk234 singhpk234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks @ebyhr @wendigo !

Not sure how easy it is it would be great to have an UT

@huaxingao
Copy link
Contributor

LGTM. +1 to add a test if possible.

Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and +1 for adding a test

@ebyhr ebyhr force-pushed the ebi/serafin/close-avro-stream branch from b282c4e to f01016a Compare October 16, 2025 12:47
@ebyhr
Copy link
Contributor Author

ebyhr commented Oct 16, 2025

I added a unit test and confirmed that it fails without this fix.

@ebyhr ebyhr force-pushed the ebi/serafin/close-avro-stream branch from f01016a to 9c049e8 Compare October 16, 2025 12:57
try (MockedStatic<AvroIO> avroIo = mockStatic(AvroIO.class)) {
avroIo.when(() -> AvroIO.stream(seekableInputStream, 100L)).thenReturn(seekableInput);

try (MockedStatic<DataFileReader> dataFileReaderMock = mockStatic(DataFileReader.class)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could move this into the upper try block and safe us one level of nesting

When avro file is malformed, DataFileReader.openReader can exit by
throwing InvalidAvroMagicException which will leave input stream open
and in the result, leaked.

Co-Authored-By: Eduard Tudenhoefner <[email protected]>
Co-Authored-By: Mateusz "Serafin" Gajewski <[email protected]>
@ebyhr ebyhr force-pushed the ebi/serafin/close-avro-stream branch from 146bf8c to 3c7ee09 Compare October 16, 2025 13:50
@singhpk234 singhpk234 merged commit f6b627c into apache:main Oct 16, 2025
42 checks passed
@singhpk234
Copy link
Contributor

Thanks for the fix @ebyhr @wendigo ! Thank you for the reviews @huaxingao and @nastra !

@ebyhr ebyhr deleted the ebi/serafin/close-avro-stream branch October 16, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants