wombatu-kun opened a new pull request, #8921: URL: https://github.com/apache/paimon/pull/8921
### Purpose Closes #8765. `FileIndexFormat.Reader` takes ownership of the `SeekableInputStream` and parses the file header in its constructor. The magic and version checks throw `RuntimeException`, but the only `catch` handled `IOException`, so those paths left the stream open. A throwing constructor hands out no reference, so the caller's try-with-resources never binds and `Reader.close()` never runs. It is reachable in production: `FileIndexEvaluator.createFileIndexPredicate` and `FileIndexProcessor` pass `fileIO.newInputStream(path)` straight into the constructor for the separate `.index` file, so a corrupt index file, or one written by a newer Paimon version, leaks one descriptor per attempt. The scan path passes the embedded index as `byte[]` and is unaffected. The fix guards the constructor with a success flag and closes the stream from `finally` when parsing did not complete. Widening the catch to `IOException | RuntimeException`, as the issue suggests, does not compile: the constructor does not declare `throws IOException`, so precise rethrow rejects `throw e`. Wrapping everything into a new `RuntimeException` would instead bury `This file is not file index file.` in the cause. The `finally` form keeps the type, message and cause of every exception unchanged, and also covers the `OutOfMemoryError` a garbage `headLength` can trigger. ### Tests Five tests in `FileIndexFormatFormatTest`, on a `ByteArraySeekableStream` subclass that counts `close()` calls: bad magic, unsupported version and corrupted head length (these three fail on master), truncated head (the `IOException` branch, where asserting exactly one close also guards against double close), and successful construction (the constructor leaves the stream open and `Reader.close()` closes it once). `mvn -pl paimon-common test -Dtest='org.apache.paimon.fileindex.**'` (69 tests) and `DataFileIndexWriterTest` in paimon-core pass, along with `spotless:check` and checkstyle. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
