Repository navigation
Fix FileNotFoundError race in clickhouse-test suite tag scan - #109120
Merged
Merged
Conversation
When several `clickhouse-test` workers run concurrently against one shared
queries directory, a worker that needs query substitutions writes a transient
per-PID copy of a test file (`<name>.<pid><ext>`, see `TestCase.temp_file_path`)
next to the original and removes it once done. Another worker's suite scan
enumerates the directory with `os.listdir` in `get_selected_tests` and reads
each file's tags via `load_tags_and_random_settings_limits_from_file`; if a
sibling worker's transient copy is listed and then deleted before this worker
opens it, the unguarded `open` raises `FileNotFoundError` and aborts the entire
run during suite construction (before any test runs).
Guard the `open` so a file that vanished mid-scan is skipped (it has no tags to
contribute) instead of crashing the whole run. Mirrors the existing
`UnicodeDecodeError` handling in the same function.
Observed as a flaky `Stress test (arm_asan_ubsan)` failure ("Test script
failed", `script exit code: 1`): one of the 8 parallel `clickhouse-test`
instances died with
`FileNotFoundError: ... 03745_buffers_input_output_format_roundtrip.4491.sh`
in `load_tags_and_random_settings_limits_from_file`, where `4491` is the PID of
a `Process-3` worker in a sibling instance.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [7d2f323] Summary: ✅ AI ReviewSummaryThis PR changes Missing context / blind spots
Final Verdict✅ No new inline findings for the current PR head. |
The earlier `FileNotFoundError` guard in `load_tags_and_random_settings_limits_from_file` only masked one symptom of the race. `SharedEngineReplacer` writes a transient per-PID copy of a test (`<name>.<pid><ext>`, see `SharedEngineReplacer.temp_file_path`) next to the original while the test runs. A concurrent `clickhouse-test` invocation's suite scan (`os.listdir` in `get_selected_tests`) can list that copy and schedule it as a real test: it then either fails as `FileNotFoundError` in `is_valid_utf_8` once the copy is deleted, or runs as a bogus PID-suffixed test reported `NO_REFERENCE`. Recognize and exclude these copies in `is_test_from_dir` (the single discovery choke point used by both `get_selected_tests` and the stress diagnosis scan) so they never enter the test list. The copy is only skipped when the original it was made from is present, which makes a false positive on a genuine test impossible: no test in the tree has a `<name>.<digits><ext>` shape. This makes the earlier `open` guard unnecessary, so it is reverted. Related: #108827 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review: the previous `is_transient_test_copy` inferred "transient copy" from the basename shape — it skipped any file named `<name>.<digits><ext>` whenever `<name><ext>` also existed. That changes `clickhouse-test` discovery semantics for valid suites: a real test named `foo.1.sql` would be silently dropped whenever `foo.sql` is also present, coupling the race fix to an undocumented restriction on genuine test names. Instead, give the transient per-PID copies created by `SharedEngineReplacer` a dedicated infix marker (`SharedEngineReplacer.TEMP_FILE_MARKER`) that no real test filename uses, and skip files carrying that marker at discovery. This recognizes the copies unambiguously without constraining the names of genuine tests: `foo.1.sql` is now discovered normally, while `foo.shared_engine_replacer_tmp.<pid>.sql` is skipped. The copy stays next to the original (same directory), so `.sh`/`.sql` tests that resolve helpers or reference files relative to their own location are unaffected. Verified by loading the real functions from `clickhouse-test`: the copy that `SharedEngineReplacer` produces is recognized by `is_transient_test_copy`, and `is_test_from_dir` discovers `foo.1.sql` (the reviewer's counterexample) while skipping the marked transient copy. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The AI review requested automated coverage for the producer/filter contract this PR introduces. `ci/tests/test_shared_engine_replacer_discovery.py` loads `tests/clickhouse-test` via `runpy.run_path`, has `SharedEngineReplacer` materialize a transient per-PID copy next to `foo.sql`, and asserts that `is_test_from_dir` skips only the marked `foo.shared_engine_replacer_tmp.<pid>.sql` while still discovering both `foo.sql` and the `foo.1.sql` look-alike that the earlier basename-shape heuristic silently dropped. Related: #108827 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…est-tag-scan-race Fix FileNotFoundError race in clickhouse-test suite tag scan
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.
Fix a flaky
Stress testfailure caused by a race inclickhouse-test's suite construction.When several
clickhouse-testinvocations run concurrently against one shared queries directory, a run that needs query substitutions writes a transient per-PID copy of a test file (<name>.<pid><ext>, seeSharedEngineReplacer.temp_file_path) next to the original and removes it once the test finishes. Another invocation's suite scan enumerates the directory withos.listdiringet_selected_testsand can observe that copy. Because the copy ends in a supported extension,is_test_from_diraccepts it and it is scheduled as a real test. It then fails in one of two ways: if the copy is deleted before the run reads its tags inload_tags_and_random_settings_limits_from_fileor checks it inis_valid_utf_8, the unguardedopenraisesFileNotFoundErrorand aborts the whole run during suite construction; if the copy is still present, it runs as a bogus PID-suffixed test with no reference file and is reportedNO_REFERENCE.This surfaced as a flaky
Stress test (arm_asan_ubsan)failure (Test script failed,script exit code: 1): one of the 8 parallelclickhouse-testinstances died withFileNotFoundError: ... 03745_buffers_input_output_format_roundtrip.4491.shinload_tags_and_random_settings_limits_from_file, where4491is the PID of aProcess-3worker in a sibling instance. There was no server crash, sanitizer report, or logical error.The fix recognizes and excludes these transient copies at the single discovery choke point,
is_test_from_dir, so they never enter the test list.SharedEngineReplacerembeds a dedicated infix marker (SharedEngineReplacer.TEMP_FILE_MARKER) into the per-PID copies it writes (<name>.shared_engine_replacer_tmp.<pid><ext>), andis_transient_test_copyskips only the files carrying that marker. The marker is a namespaceclickhouse-testowns and no real test filename uses, so this recognizes the copies unambiguously without inferring "transient copy" from the basename shape and thus without constraining the names of genuine tests — a real test such asfoo.1.sqlis discovered normally even whenfoo.sqlis also present. The copy stays next to the original, so.sh/.sqltests that resolve helpers or reference files relative to their own location are unaffected. Excluding the copy at discovery also removes the need for aFileNotFoundErrorguard inload_tags_and_random_settings_limits_from_file, so the earlier guard is reverted rather than left as a fallback that only masked one symptom.Found while reviewing the CI report of #108827 (the failure was unrelated to that PR, which only touches CI tooling).
Related: #108827
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Documentation entry for user-facing changes
Version info
26.7.1.452(included in26.7and later)