Repository navigation
Cherry pick #114668 to 25.8: Stop Parquet background reads before releasing the format's read buffer - #114874
Conversation
A dictionary that reads Parquet from a local file hands its ReadBuffer to the input format via IInputFormat::addBuffer(), so the format owns it in owned_buffers. When the pipeline finishes, ISource::work() calls onFinish() on both the clean (ISource.cpp:133) and the exception (ISource.cpp:140) path, which reaches IInputFormat::resetReadBuffer() and clears owned_buffers, destroying the buffer. ParquetV3BlockInputFormat did not override that hook, and Parquet::Prefetcher holds a non-owning SeekableReadBuffer* to the same buffer (Prefetcher.h:175). Background prefetch and decode tasks therefore kept reading through a destroyed object. Prefetcher.cpp:111 is a virtual call on it, so the 8-byte read is the freed vptr; observed both as an AddressSanitizer heap-use-after-free in Prefetcher::readSync and as a libc++abi pure-virtual abort. ~Prefetcher() does perform the correct shutdown handshake, but only at format destruction, which is strictly later than onFinish(); the window between the two is the bug. The hook is resetReadBuffer() rather than onFinish() because it is what actually frees the buffers and it has a second caller, StreamingFormatExecutor::execute()'s SCOPE_EXIT. Two task families need draining, not one: Prefetcher's IO tasks and ReadManager's decode tasks, which re-enter readSync inline via getRangeData(). ReadManager is drained first, since it produces the tasks that reach the prefetcher. The reader itself is kept alive, because getMatchedBuckets() reads row group metadata after the source is exhausted to populate the query condition cache. This mirrors ParallelParsingInputFormat::onFinish(), which waits for its threads for the same reason. Found by the La Casa Del Dolor (arm_asan_ubsan) fuzzer check. Reachable without a fuzzer: ReadBufferFromFile leaves use_pread false, so a plain local file takes the SeekAndRead path, and any CREATE DICTIONARY ... SOURCE(FILE(... format 'Parquet')) whose load throws hits it. Co-Authored-By: Claude Fable 5 <[email protected]>
The regression test passed on the unfixed binary most of the time because it did not exercise what its comments claimed. Two independent defects, both confirmed by measurement before being changed. The five-iteration loop performed a single real load: once the dictionary is FAILED, a non-forced dictGet cannot re-enter startLoading, because getMinIDToFinishLoading(false) returns 1 while loading_id is already at least 1, so checkLoaded rethrows the stored exception. Nothing filled the gap inside one run, since a failed load pins the next update five seconds out and the periodic updater's own period is also five seconds. Counting error messages could not see this, as the replayed message is byte-identical. Per-iteration prefetcher reads were 93, 0, 0, 0, 0; with SYSTEM RELOAD DICTIONARY, which forces a reload, they are 85, 90, 85, 86, 83. The three race-widening settings never reached the load either. A dictionary loads in the global context, and the file source only applies the DDL SETTINGS clause, so the format was built from defaults. Moving min_bytes_for_seek into that clause changes the per-reload read count from 87 to 241 at 1 and to 2 at 100000000, while the same value on the client command line does not change it at all. A typo'd name inside the clause is silently ignored, which is the negative control that a dead clause cannot look like a live one. With both fixed the test still reddened rarely, so the remaining difference against the standalone reproducer was isolated: at 2000000 rows it survives five forced reloads with 8 threads and dies with 32, so concurrency carries the window, not fixture size. The test now reddens 7 of 7 scored runs on the unfixed binary, all of them a pure-virtual abort at Prefetcher.cpp:111, and passes 11 of 11 fixed plus 50 of 50 randomized runs. A local unfixed run also produced a full heap-use-after-free whose symbolized stack matches the CI report frame for frame, including both thread names and the 272-byte region. The loop is now guarded by a control that reads per-query ProfileEvents from system.query_log, so each of the five reloads is proven to have reached the reader. The global system.events counter was rejected as pollutable on a shared server, and system.dictionaries.error_count as unreliable, since the periodic updater also increments it. The long tag is dropped because it costs 90 percent of the flaky check's repeats, and the test measures 16 to 24 seconds against a 180 second threshold. The only source change is a comment trim. Co-Authored-By: Claude Fable 5 <[email protected]>
The test asserted ParquetPrefetcherReadSeekAndRead > 0 per reload, but that counter is also incremented by the two synchronous footer reads in Reader::readFileMetaData, so a load rejected while its footer was parsed satisfied the assertion without ever reading a row group. Measured on a file with a corrupt footer length: the old assertion passed 5 of 5 while no row group was read. ParquetReadRowGroups is counted once row groups are being read, and measured 397 on 20 of 20 reloads of this fixture, so it separates the two cases without making the test timing dependent. Pin input_format_parquet_enable_row_group_prefetch so the prefetch pool exists regardless of a server side or future default: without it Prefetcher::scheduleTask does nothing and getRangeData runs the read inline on the decoding thread, which no read counter distinguishes. Renumber to 04895, since 04885 was taken first by another unmerged test.
Content half of the previous commit, which recorded only the rename.
The style check rejects a bare global SYSTEM FLUSH LOGS (ci/jobs/scripts/check_style/various_checks.sh:192): flushing every log table on the server disturbs tests running in parallel. The test only reads system.query_log, so name that table. Verified the scoped form is effective rather than silently ignored: the log name is parsed and validated, so a wrong name errors with BAD_ARGUMENTS, and with the flush removed entirely the reloads_that_read oracle reads 0 instead of 5, i.e. the flush is load-bearing for the assertion.
…r-lifetime Stop Parquet background reads before releasing the format's read buffer
|
The four Simulating the cherry-pick per branch ( 25.8 conflicts in There is also a reachability difference. On 25.8 I have not touched the cherry-pick branch: per @ pufit's standing instruction I do not hand-resolve release-branch ports. @PedroTadim you applied the backport label, so this is your call. My suggestion is to close #114874 and leave 25.8 unfixed, since the reader is experimental and off by default there. If you do want 25.8 covered, it needs a hand-adapted variant plus its own test guard rather than this cherry-pick, and I can write that if you ask. Test number 04895 is free on all five branches. |
…ypick/25.8/114668 # Conflicts: # src/Processors/Formats/Impl/Parquet/ReadManager.h
|
🕵 Resolved the conflict with a hand-adapted 25.8 variant. The merge adds the missing reader synchronization around initialization, cancellation, parser reset, and read-buffer reset; it stops The branch is pushed at |
Original pull-request #114668
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job