Fix CDM_Application::myMetaDataLookUpTable/CDM_MetaData reentrancy races (#1396)#1397
Open
gsdali wants to merge 2 commits into
Open
Fix CDM_Application::myMetaDataLookUpTable/CDM_MetaData reentrancy races (#1396)#1397gsdali wants to merge 2 commits into
gsdali wants to merge 2 commits into
Conversation
CDM_Application::myMetaDataLookUpTable is shared process-wide (via the CDM_Application/CDF_Application singleton) with no synchronization on its map accesses (CDM_MetaData::LookUp, CDM_Document::SetMetaData's iteration) or on individual CDM_MetaData objects' myIsRetrieved/myDocument fields. Add a mutex on CDM_Application guarding the map, threaded through every access point, plus a private mutex on CDM_MetaData guarding its own fields.
This was referenced Jul 23, 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.
Fixes #1396.
CDM_Application::myMetaDataLookUpTableis shared process-wide (oneCDM_Application/CDF_Applicationinstance per process, per the singleton pattern fixed in #1389/#1390) with zerosynchronization on its map accesses or on the individual
CDM_MetaDataobjects it hands out. See#1396 for the full trace and TSan evidence (1 confirmed race + SIGABRT → 0 races with this patch).
Fix
CDM_Applicationgets amutable std::mutex myMetaDataLookUpTableMutex+MetaDataLookUpTableMutex()accessor, threaded through every access point:CDM_MetaData::LookUp()'s two overloads (now take the mutex as an explicit parameter alongsidethe map, since they're
staticand operate on a caller-supplied table+mutex pair),CDF_FWOSDriver's constructor/call sites,XmlLDrivers_DocumentRetrievalDriver:: ReadFromDomDocument, andPCDM_ReferenceIterator::MetaData.CDM_Document::SetMetaData()'sfull-table iteration is now guarded for its duration.
CDM_MetaDatagets its own privatemutable std::mutex myDocumentMutexguardingmyIsRetrieved/myDocument, sinceSetDocument/UnsetDocument/IsRetrieved/Documentarecalled on one shared
CDM_MetaDatainstance from whichever thread looked it up and,independently, from another thread's document destructor.
Testing
DataExchange): 1 confirmed race + SIGABRT (exit 134) on unpatched master → 0 races, clean exit,
across repeated runs (8×25, 10×60, 3×8×40 thread/round configurations).
https://github.com/SecondMouseAU/OCCTSwift/tree/main/Scripts/repro/353-cdm-metadata-lookup-table