Geethapranay1 opened a new pull request, #3435: URL: https://github.com/apache/fory/pull/3435
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` <!-- **Thanks for contributing to Apache Fory™.** **If this is your first time opening a PR on fory, you can refer to [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).** Contribution Checklist - The **Apache Fory™** community has requirements on the naming of pr titles. You can also find instructions in [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md). - Apache Fory™ has a strong focus on performance. If the PR you submit will have an impact on performance, please benchmark it first and provide the benchmark result here. --> ## Why? <!-- Describe the purpose of this PR. --> 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? <!-- Describe the details of this PR. --> * 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 <!-- Is there any related issue? If this PR closes them you say say fix/closes: - #xxxx0 - #xxxx1 - Fixes #xxxx2 --> ## Does this PR introduce any user-facing change? <!-- If any user-facing interface changes, please [open an issue](https://github.com/apache/fory/issues/new/choose) describing the need to do so and update the document if necessary. Delete section if not applicable. --> 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 <!-- When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here. Delete section if not applicable. --> after updating code changes cargo build successful <img width="974" height="112" alt="Screenshot From 2026-02-28 14-59-24" src="https://github.com/user-attachments/assets/db3b9bb3-4f04-4339-aeed-4ad0351522ac" /> testing with new test file successfully passed all testcases <img width="978" height="525" alt="Screenshot From 2026-02-28 15-00-21" src="https://github.com/user-attachments/assets/e9f20643-f84d-4f1a-a694-c80567fde0b8" /> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
