Skip to content

Fix formatter registration race on first access - #471

Open
sean0407 wants to merge 1 commit into
Cysharp:mainfrom
sean0407:codex/memorypack-458-parallel-deserialize-20261020
Open

sean0407 wants to merge 1 commit into
Cysharp:mainfrom
sean0407:codex/memorypack-458-parallel-deserialize-20261020

Conversation

@sean0407

Copy link
Copy Markdown

Summary

- publish registered=true before the formatter cache is ready
+ publish the formatter in the type map, then release-publish registered=true
+ fall back to the published formatter if the generic cache is still null

Register<T> now writes the formatter before publishing registration with Volatile.Write. GetFormatter<T> uses the published formatter map when a concurrent first lookup observes an empty generic cache. IsRegistered<T> and the cache initializer use acquire reads.

Evidence

  • Before: the focused concurrency regression failed; multiple fresh generic types returned a null formatter after IsRegistered<T>() became true.
  • After: the same focused regression passed across 128 fresh generic types with eight concurrent readers.
  • Full MemoryPack.Tests suite: 158 passed, 0 failed.
  • Changed src/MemoryPack.Core/MemoryPackFormatterProvider.cs and tests/MemoryPack.Tests/ProviderTest.cs.

Merge Danger

Door: two-way

Blast Radius: localized

Only formatter registration publication and the associated concurrency regression test change.

Fixes #458

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.

NullReferenceException on parallel Deserialize

1 participant