Skip to content

fix(python): preserve shared readers when closing dataframe subsets - #946

Merged
ColinLeeo merged 2 commits into
apache:developfrom
ColinLeeo:fix/tree-query-segfault
Sep 8, 2026
Merged

ColinLeeo merged 2 commits into
apache:developfrom
ColinLeeo:fix/tree-query-segfault

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Closing or collecting a subset TsFileDataFrame in the default use_index=False mode closes the readers shared with its parent. The parent remains marked open, so a later .loc query can pass a null reader into query_table_on_tree and segfault. A temporary boolean-filter view is enough to trigger this with an ordinary English device name; it is still reproducible on #942.

Keep direct-reader ownership on the root dataframe: closing a subset invalidates only that subset. Reads through a direct subset or its Timeseries now check whether the root has been explicitly closed and raise RuntimeError before entering native code. Indexed subsets retain their existing independent runtime leases.

Add 18 subprocess-isolated regressions covering tree/table models, both index modes, explicit close, garbage collection, context-manager exit, temporary filtering, sibling/nested views, and reads after root closure. Before the fix, 10 of these fail; all 18 pass with the fix.

Validation:

  • Fresh C++ and Cython build; cd python && python -m pytest tests -q --tb=short: 259 passed.
  • Black 25.11.0 (Python 3.9 CI) and Black 26.3.1: all 42 Python files pass both checks; git diff --check passes. The formatting follow-up preserves the Python AST.
  • Original Linux QA crash case and all 18 new regressions pass when the two changed methods are loaded into temporary test processes against the original native library. The installed package was not modified.
  • External Linux QA completes: 267 passed, 5 skipped, 4 failed. All four remaining failures also reproduce on the unmodified baseline: three duplicate-timestamp expectations and one expectation of the old subset-close no-op warning.

@ColinLeeo
ColinLeeo merged commit b760c33 into apache:develop Sep 8, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant