Repository navigation
[Data] Fix read_mcap planning deadlock behind flaky test_mcap_data_column - #68419
Merged
goutamvenkat-anyscale merged 2 commits intoNov 23, 2026
Conversation
…lumn Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
AarryaSaraf
marked this pull request as ready for review
November 21, 2026 00:05
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the read_summaries function in mcap_summary.py by replacing the with ThreadPoolExecutor context manager with an explicit try...finally block that shuts down the executor with wait=False and cancel_futures=True. This prevents potential deadlocks during garbage collection when the generator is closed while a thread holds a lock needed for joining. I have no feedback to provide as there are no review comments.
goutamvenkat-anyscale
approved these changes
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
read_mcapplanning can deadlock on Python 3.12 when it skips a file that isn't MCAP and then stops early. That is whytest_mcap_data_columntimes out intermittently: postmerge build 21143 showsTIMEOUT in 2 out of 2, both attempts stuck intest_unreadable_sampled_file_is_skipped, while the file normally passes in 3–5 s.read_summariesnow shuts its thread pool down without joining the workers.Before
read_summaries(mcap_summary.py) is a generator that owns aThreadPoolExecutorin awithblock, so closing it joins the workers. Since #67930 ("read neighbouring chunks in one ranged request"), a failed summary read leaves its error in a reference cycle: the section task re-raises the tail read's error, and that error's traceback holds the task's frame, which holds the tail future. The traceback also holds the_summariesframe, whosesectionslocal holds the generator.So when
_FileInspector.walkreturns early after skipping such a file, the generator is closed later by the cyclic garbage collector, on whichever thread triggers it. Every new thread callsthreading._maintain_shutdown_lockswhile holding_shutdown_locks_lock. If the collection starts there, the join waits for that same lock, and the thread hangs:In the test file,
test_walk_skips_unreadable_files_and_stops_at_its_capleaves such a generator behind, and the next test hangs when it starts threads.After
read_summariescreates the pool directly and callspool.shutdown(wait=False, cancel_futures=True)in afinally. Closing the generator never joins a thread, whichever thread or code path closes it. Pending reads are cancelled and in-flight ones finish on their own. Callers consume every future as it is yielded, so none of them relied on the join.flowchart TD subgraph Before subgraph BS[IO: read_mcap planning, read_summaries] B1[walk returns early after a skipped file] -->|error traceback keeps the generator alive| B2[cyclic GC closes the generator] B2 -->|with-block exit| B3["shutdown(wait=True): joins workers"] end end subgraph After subgraph AS[IO: read_mcap planning, read_summaries] A1[walk returns early after a skipped file] -->|error traceback keeps the generator alive| A2[cyclic GC closes the generator] A2 -->|finally| A3["shutdown(wait=False, cancel_futures=True): no join"] end end classDef removed fill:#ffcdd2,stroke:#c62828,color:#000 classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 class B3 removed class A3 addedThe real
read_summaries,_SectionWindow,_summariesand_FileInspector.walkfrom each revision, with file I/O stubbed, running 3,000 rounds of "walk past a non-MCAP file, then start new threads" undergc.set_threshold(1, 1, 1):walk()returnsmasterSubsystems
IO (
_internal/datasource_v2/formats/mcap/mcap_summary.py)Testing
ruff check,black --check,pydoclintandgit diff --checkon the change: clean. Pyrefly in CI's environment: 0 errors.test_mcap_data_column.pywas not run locally (nomcapin my environment); CI runs it.Not a duplicate: no open PR touches
read_summariesor this test. #68109 fixed a different failure in this file (struct field order under pyarrow 25).AI assistance was used; I reviewed every changed line.
Signed-off-by: Aarrya [email protected]
🤖 Generated with Claude Code