Skip to content

feat(rust): forbid late type registration after resolver snapshot ini…#3435

Open
Geethapranay1 wants to merge 2 commits intoapache:mainfrom
Geethapranay1:feat/lifecycle-guard-registration
Open

feat(rust): forbid late type registration after resolver snapshot ini…#3435
Geethapranay1 wants to merge 2 commits intoapache:mainfrom
Geethapranay1:feat/lifecycle-guard-registration

Conversation

@Geethapranay1
Copy link

@Geethapranay1 Geethapranay1 commented Feb 28, 2026

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

Why?

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?

  • adds a lifecycle guard (check_registration_allowed) to all type registration entry points in fory.
  • after the first serialize/deserialize call, any further registration attempts return Error::NotAllowed with a descriptive message.
  • prevents silent bugs where late registrations appear to succeed but are ignored at runtime.
  • adds comprehensive tests to verify both positive and negative cases for all registration methods.

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

Related 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.

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

after updating code changes cargo build successful
Screenshot From 2026-02-28 14-59-24

testing with new test file successfully passed all testcases
Screenshot From 2026-02-28 15-00-21

…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
@Geethapranay1
Copy link
Author

Hi @chaokunyang,

Could u please check with this any further improvements?

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.

rust: forbid late registration after resolver snapshot initialization

1 participant