You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "Swatantra-66 (via GitHub)" <gi...@apache.org> on 2026/10/09 19:17:01 UTC

[PR] [Go] Enforce registration freeze after first root serialize/deserialize operation (#4118) [fory]

Swatantra-66 opened a new pull request, #4161:
URL: https://github.com/apache/fory/pull/4161

   ## Why?
   
   In Go, `Fory` previously allowed registering structs, enums, unions, and extensions after root serialization or deserialization had already begun. This violated Fory's registration lifecycle design invariant, invalidated precomputed type descriptors and resolver state, and introduced subtle race conditions in shared/concurrent usage.
   
   ## What does this PR do?
   
   Enforces permanent registration freeze on `Fory` instances upon the first root serialize or deserialize operation:
   
   1. **Export Sentinel Error**:
      - Defines `var ErrRegistrationFrozen = errors.New("fory: registration is frozen after serialization or deserialization has started")`.
   2. **State & Methods**:
      - Adds `frozen bool` state and `Freeze()`, `IsFrozen() bool` methods to both `Fory` and `TypeResolver`.
   3. **Registration Guards**:
      - Guards all 8 public registration methods (`RegisterStruct`, `RegisterUnion`, `RegisterEnum`, `RegisterExtension`, and their `ByName` variants) in `Fory` and `TypeResolver` to reject post-freeze calls immediately before any reflection or map mutation occurs.
   4. **Root Operation Hooks**:
      - Automatically triggers `Freeze()` at the entry points of all root serialization and deserialization APIs (`Serialize`, `SerializeTo`, `Marshal`, `SerializeWithCallback`, `Serialize[T]`, `Deserialize`, `DeserializeFrom`, `Unmarshal`, `DeserializeWithCallbackBuffers`, `Deserialize[T]`, `DeserializeFromStream`, and `DeserializeFromReader`).
   5. **ThreadSafe Wrapper**:
      - Standardizes `threadsafe.Fory` to return `fory.ErrRegistrationFrozen`.
   6. **Tests**:
      - Adds comprehensive unit tests (`TestRegistrationFreeze`, `TestIssue4118Reproducer`, and `TestIssue4118FailedRootOperationFreezes`) verifying:
        - Pre-operation registrations succeed.
        - All 8 registration methods return `ErrRegistrationFrozen` after root serialize or deserialize operations.
        - Failed serialize/deserialize attempts still permanently freeze registration.
        - Rejected late registrations leave internal resolver maps and type tables completely unmutated.
        - Generic and streaming APIs properly trigger freeze.
   
   ## Related issues
   
   Closes #4118
   
   ## AI Contribution Checklist
   
   - [x] Substantial AI assistance was used in this PR: `no`
   
   ## Does this PR introduce any user-facing change?
   
   - [x] Does this PR introduce any public API change? Exports `ErrRegistrationFrozen` and methods `Freeze()`, `IsFrozen()`.
   - [ ] Does this PR introduce any binary protocol compatibility change? No.
   
   ## Benchmark
   
   All existing Go tests and benchmarks run cleanly without regressions.
   


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(go): Enforce registration freeze after first root serialize/deserialize operation [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #4161:
URL: https://github.com/apache/fory/pull/4161


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org