Repository navigation
[TEST][RUST] Register the reflection test types before any test reads… - #862
Merged
tqchen merged 1 commit intoOct 22, 2026
Conversation
… them The types in test_object_reflection.rs register on first use, while tests on other threads read the type table. The runtime grows the table without a lock, so a reader can see a moved-out or freed entry: Windows CI failed with "Cannot find type info for type_index=139", and 16 of 500 local runs crashed. Each test now first registers every type of the file, once, behind a `Once`. No run failed out of 2000.
tqchen
approved these changes
Oct 21, 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
Fix a flaky crash in the Rust test
test_object_reflection(added in #859).It failed the Windows job of the
mainCI run39440570092:
Cause
#[type_register]types register on first use. Intest_object_reflection.rsthat first use happens inside the tests, which cargo runs on several threads,
so one test registers a type while another reads the type table
(
TVMFFIGetTypeInfo,is_instance_of,ffi.StructuralEqual, ...).TYPE_REGISTRATIONkeeps registrations from running at the same time, but itdoes not block readers, and the runtime does not lock its type table. Each
type registered in the dynamic range grows
type_table_(src/ffi/object.cc):the vector reallocates, moves every entry out of the old buffer and frees it.
A reader still on the old buffer sees a null entry (the error above, after
which the process exits) or freed memory (a segfault, seen locally in
is_instance_of,StructuralEqual::EqualandStructuralHash::Hash).Changes
register_types()registers the four types of the file (PointObj,Point3Obj,CounterObj,LeafObj) once, behind astd::sync::Once, andeach test calls it first. All registrations then finish before any test
reads the table. The tests still run in parallel.
Not changed
while another thread uses tvm-ffi can still hit this race. This PR only
removes it from the tests.
test_object_registration.rsandtest_match_any_ast_lookup.rsalsoregister types on first use. Neither failed in 1000 local runs, so they are
unchanged.
Tests
Local runs of the
test_object_reflectionbinary on Linux:--test-threads=1pre-commit is clean.