Make circular type forwarder protection thread-safe #978

Open
ItsZil wants to merge 1 commit from Unity-Technologies/circular-type-thread-safe into master
ItsZil commented 2026-03-10 10:49:53 -05:00 (Migrated from github.com)

PR https://github.com/jbevain/cecil/pull/806 added protection against circular type forwarders using an instance-level bool reentrancyGuard variable. This created race conditions when multiple threads resolved the same ExportedType.

This PR replaces the bool with a [ThreadStatic] static int reentrancyDepth counter, allowing forwarding up to const int MaxForwardingDepth = 16 depth, which is thread-safe and supports legitimate forwarding chains.

I added a test (TypeForwarderMultiLevel) that resolves a simple forwarding chain.

PR https://github.com/jbevain/cecil/pull/806 added protection against circular type forwarders using an instance-level `bool reentrancyGuard` variable. This created race conditions when multiple threads resolved the same `ExportedType`. This PR replaces the bool with a `[ThreadStatic] static int reentrancyDepth` counter, allowing forwarding up to `const int MaxForwardingDepth = 16` depth, which is thread-safe and supports legitimate forwarding chains. I added a test (`TypeForwarderMultiLevel`) that resolves a simple forwarding chain.
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'Unity-Technologies/circular-type-thread-safe:Unity-Technologies/circular-type-thread-safe'
git switch 'Unity-Technologies/circular-type-thread-safe'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'master'
git merge --no-ff 'Unity-Technologies/circular-type-thread-safe'
git switch 'Unity-Technologies/circular-type-thread-safe'
git rebase 'master'
git switch 'master'
git merge --ff-only 'Unity-Technologies/circular-type-thread-safe'
git switch 'Unity-Technologies/circular-type-thread-safe'
git rebase 'master'
git switch 'master'
git merge --no-ff 'Unity-Technologies/circular-type-thread-safe'
git switch 'master'
git merge --squash 'Unity-Technologies/circular-type-thread-safe'
git switch 'master'
git merge --ff-only 'Unity-Technologies/circular-type-thread-safe'
git switch 'master'
git merge 'Unity-Technologies/circular-type-thread-safe'
git push origin 'master'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil!978
No description provided.