feat(rust): forbid late type registration after resolver snapshot ini…#3435
Open
Geethapranay1 wants to merge 2 commits intoapache:mainfrom
Open
feat(rust): forbid late type registration after resolver snapshot ini…#3435Geethapranay1 wants to merge 2 commits intoapache:mainfrom
Geethapranay1 wants to merge 2 commits intoapache:mainfrom
Conversation
…tialization Add a lifecycle guard to all registration entry points in fory. After the first serialize/deserialize call initializes the final_type_resolver (OnceLock), any subsequent register* call returns Error::NotAllowed with a descriptive message. this prevents a silent footgun where late registrations appear to succeed but are never reflected in the frozen resolver snapshot. Guarded methods: - register, register_union - register_by_name, register_union_by_name - register_by_namespace, register_union_by_namespace - register_serializer, register_serializer_by_name, register_serializer_by_namespace - register_generic_trait closes apache#3417
Author
|
Hi @chaokunyang, Could u please check with this any further improvements? |
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.
Add a lifecycle guard to all registration entry points in fory. After the first serialize/deserialize call initializes the
final_type_resolver(OnceLock), any subsequentregister*call returnsError::NotAllowedwith a descriptive message.this prevents a silent footgun where late registrations appear to succeed but are never reflected in the frozen resolver snapshot.
Guarded Methods
register,register_unionregister_by_name,register_union_by_nameregister_by_namespace,register_union_by_namespaceregister_serializer,register_serializer_by_name,register_serializer_by_namespaceregister_generic_traitWhy?
After the first serialize/deserialize call, Fory's
final_type_resolver(OnceLock) is frozen. Any subsequent type registration calls (register*) silently succeed but do not affect the frozen resolver, leading to confusing runtime errors.this PR introduces a lifecycle guard to prevent late registration and make the lifecycle explicit and fail-fast.
What does this PR do?
check_registration_allowed) to all type registration entry points in fory.Error::NotAllowedwith a descriptive message.Guarded Methods
register,register_unionregister_by_name,register_union_by_nameregister_by_namespace,register_union_by_namespaceregister_serializer,register_serializer_by_name,register_serializer_by_namespaceregister_generic_traitRelated issues
Closes #3417
Does this PR introduce any user-facing change?
Yes. users will now receive a clear error if they attempt to register types after the resolver snapshot is initialized, instead of silent failure.
Benchmark
after updating code changes cargo build successful

testing with new test file successfully passed all testcases
