Fix concurrent HashSet modification when serializing archive meta#618
Merged
Conversation
UpdateMeta, UpdateTags and Update(ExchangeInfo) all touched _archiveMetaInformation.Tags but guarded it with two different locks (one on the path string, another on the meta object itself), so a thread adding a tag could race a thread serializing the meta file and trip "Collection was modified" inside JsonSerializer. Route every access through a single _metaLock and keep UpdateMeta inside the lock.
This was referenced Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DirectoryArchiveWriterguarded_archiveMetaInformation.Tagswith two different locks:UpdateMetaandUpdateTagslocked on the path string, whileUpdate(ExchangeInfo)locked on the meta object itself. That meant two threads could be inside the tag code at the same time, one adding to the HashSet while the other was enumerating it throughJsonSerializer.Serialize, which throws "Collection was modified; enumeration operation may not execute".The issue shows up more often when
UseDnsOverHttpsActionis enabled because every DoH query becomes its own captured exchange, roughly doubling the concurrent write traffic through the archive writer.This PR routes every access through a single
_metaLockand keeps theUpdateMeta(true)call inside the lock so the Add and the serialize never interleave. The lock on an interned string was also a latent issue and is gone.