Repository navigation
fix(cpp): return error when querying a closed TsFileReader - #1151
Merged
Merged
Conversation
Calling query() (or queryByRow, query_prepared, prepare_series) after close() dereferenced the already-deleted internal executor and crashed with SIGSEGV. Guard every query/execute entry point against a null executor and return E_INVALID_ARG, matching the existing closed-state guards in get_all_devices() and prepare_table_series().
The CI spotless/clang-format check flagged a line over 80 columns. Break the ASSERT_EQ macro arguments onto separate lines.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An active finding identifies a result-set leak when cleanup occurs after reader closure, requiring deletion independent of executor lifetime and a regression test for that sequence.
1 open issue
What changed in this PR
This PR adds closed-state checks to the C++ TsFileReader query and preparation APIs so they return E_INVALID_ARG instead of accessing a deleted executor.
Changes:
- Guard tree, table, and prepared-query entry points against a missing executor.
- Make result-set cleanup return early when the executor is absent.
- Add a regression test covering successful querying followed by post-close query errors.
| File | Description |
|---|---|
cpp/test/reader/tsfile_reader_test.cc |
Tests post-close errors for path-list query() and queryByRow(). |
cpp/src/reader/tsfile_reader.cc |
Adds closed-state guards to query, preparation, and cleanup methods. |
Review effort: Balanced
Comment on lines
+572
to
+574
| if (tsfile_executor_ == nullptr) { | ||
| return; | ||
| } |
destroy_query_data_set() early-returned when the executor was gone, leaking the result set for the sequence result->close(); reader.close(); destroy_query_data_set(result). Delete it directly so cleanup no longer depends on executor lifetime, and add a regression test.
Clarify that deleting a result set after reader close is only safe once result->close() has released its borrows from the deleted io_reader_.
# Conflicts: # cpp/test/reader/tsfile_reader_test.cc
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.

Problem
Calling
query()(orqueryByRow,query_prepared,prepare_series) on aTsFileReaderafterclose()dereferenced the already-deleted internalexecutor (
tsfile_executor_) and crashed with a segfault instead of returninga clear error.
Fix
Guard every query/execute entry point against a null
tsfile_executor_andreturn
E_INVALID_ARG, matching the existing closed-state guards inget_all_devices()andprepare_table_series().Test
Added
TsFileReaderTest.QueryAfterCloseReturnsError: open a reader, querysuccessfully, close it, then query again and assert
E_INVALID_ARG(no crash).