Skip to content

Fix CDM_Application::myMetaDataLookUpTable/CDM_MetaData reentrancy races (#1396)#1397

Open
gsdali wants to merge 2 commits into
Open-Cascade-SAS:masterfrom
gsdali:fix/353-cdm-metadata-lookup-table-race
Open

Fix CDM_Application::myMetaDataLookUpTable/CDM_MetaData reentrancy races (#1396)#1397
gsdali wants to merge 2 commits into
Open-Cascade-SAS:masterfrom
gsdali:fix/353-cdm-metadata-lookup-table-race

Conversation

@gsdali

@gsdali gsdali commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #1396.

CDM_Application::myMetaDataLookUpTable is shared process-wide (one CDM_Application/
CDF_Application instance per process, per the singleton pattern fixed in #1389/#1390) with zero
synchronization on its map accesses or on the individual CDM_MetaData objects it hands out. See
#1396 for the full trace and TSan evidence (1 confirmed race + SIGABRT → 0 races with this patch).

Fix

  1. CDM_Application gets a mutable std::mutex myMetaDataLookUpTableMutex +
    MetaDataLookUpTableMutex() accessor, threaded through every access point:
    CDM_MetaData::LookUp()'s two overloads (now take the mutex as an explicit parameter alongside
    the map, since they're static and operate on a caller-supplied table+mutex pair),
    CDF_FWOSDriver's constructor/call sites, XmlLDrivers_DocumentRetrievalDriver:: ReadFromDomDocument, and PCDM_ReferenceIterator::MetaData. CDM_Document::SetMetaData()'s
    full-table iteration is now guarded for its duration.
  2. CDM_MetaData gets its own private mutable std::mutex myDocumentMutex guarding
    myIsRetrieved/myDocument, since SetDocument/UnsetDocument/IsRetrieved/Document are
    called on one shared CDM_MetaData instance from whichever thread looked it up and,
    independently, from another thread's document destructor.

Testing

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

CDM_Application::myMetaDataLookUpTable and CDM_MetaData fields unsynchronized (race under concurrent document save/close)

1 participant