Skip to content

Stop copied settings sharing mutations of the source serialization - #1895

Merged
SimonCropp merged 1 commit into
mainfrom
fix-settings-serialization-alias
Aug 29, 2026
Merged

Stop copied settings sharing mutations of the source serialization#1895
SimonCropp merged 1 commit into
mainfrom
fix-settings-serialization-alias

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

SerializationSettings is copy on write: the first serialization mutation on a VerifySettings clones the global instance and sets isCloned, after which that instance mutates its own copy in place.

The copy constructor assigned that same instance to the copy without clearing isCloned on the source, so every later mutation of the source was applied in place and observed by the copy:

settings.IgnoreMember("A");
var copy = new VerifySettings(settings);
settings.IgnoreMember("B"); // also ignored by copy

This also hit the eager copy the SettingsTask constructor takes, when the original settings were mutated between two Verify calls.

The source is now marked as no longer the exclusive owner, so it clones before its next mutation. Sharing until either side writes keeps the copy allocation free, which matters since a copy is taken per verification.

SerializationSettings is copy on write: the first serialization mutation on a
VerifySettings clones the global instance and sets isCloned, after which that
instance mutates its own copy in place.

The copy constructor assigned that same instance to the copy without clearing
isCloned on the source, so every later mutation of the source was applied in
place and observed by the copy:

    settings.IgnoreMember("A");
    var copy = new VerifySettings(settings);
    settings.IgnoreMember("B"); // also ignored by copy

This also hit the eager copy the SettingsTask constructor takes, when the
original settings were mutated between two Verify calls.

The source is now marked as no longer the exclusive owner, so it clones before
its next mutation. Sharing until either side writes keeps the copy allocation
free, which matters since a copy is taken per verification.
@SimonCropp SimonCropp added this to the 33.0.0 milestone Aug 29, 2026
@SimonCropp
SimonCropp merged commit 83d9899 into main Aug 29, 2026
6 of 7 checks passed
@SimonCropp
SimonCropp deleted the fix-settings-serialization-alias branch August 29, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant