Fix CDF_Application-cached storage/retrieval driver reentrancy (SIGSEGV, #1393)#1394
Open
gsdali wants to merge 1 commit into
Open
Fix CDF_Application-cached storage/retrieval driver reentrancy (SIGSEGV, #1393)#1394gsdali wants to merge 1 commit into
gsdali wants to merge 1 commit into
Conversation
PCDM_StorageDriver/PCDM_Reader subclasses cached per-format by CDF_Application are not reentrant; concurrent Write()/Read() calls on the same shared instance corrupt its scratch state, causing a SIGSEGV in BinLDrivers_DocumentStorageDriver::FirstPass under concurrent Save/SaveAs of the same format. Add a mutex to each base class guarding its own Write()/Read(), held at the three call sites that use a cached, possibly-shared driver.
This was referenced Jul 22, 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 #1393.
CDF_Application::WriterFromFormat/ReaderFromFormatcache one storage/retrieval driver instanceper format and hand the same instance back to every subsequent
Store()/Retrieve()call forthat format — including from different threads, different documents, concurrently.
PCDM_StorageDriver/PCDM_Readersubclasses (e.g.BinLDrivers_DocumentStorageDriver) are notreentrant:
Write()/Read()mutate instance-level scratch state with no synchronization, so twothreads calling
Write()on the same cached instance corrupt it — reliably reproducible SIGSEGV,see #1393 for the full trace and TSan evidence (136 race warnings → 0 with this patch).
CDF_StoreList::Storealready carries a comment acknowledging multi-threaded access to the driver("It has sense in multi-threaded access to the storage driver..."), but only the store-status was
ever actually made safe for concurrent use — every other member of the driver races freely.
Fix
Adds a
mutable std::mutex+Mutex()accessor toPCDM_StorageDriverandPCDM_Reader, so everyconcrete format driver (
BinLDrivers,XmlLDrivers,BinXCAFDrivers,XmlXCAFDrivers,TObjvariants, ...) inherits the guard for free — no changes needed in any subclass. The three places
CDF_Application/CDF_StoreListinvoke a cached driver'sWrite()/Read()now hold that driver'sown mutex for the call:
CDF_StoreList::Store,CDF_Application::Retrieve,CDF_Application::Read.This targets the actual shared resource (the cached driver instance) rather than a broad lock
around unrelated code, and doesn't serialize unrelated formats against each other — a
"BinOcaf"save and an unrelated
"Xml"save use different cached driver instances and different mutexes.Testing
occt_349_barrier.cpp, N threads racingTDocStd_Application::SaveAs()on a sharedapplication): SIGSEGV within the first few hundred rounds at just 2 threads on unpatched master;
clean across repeated runs with this patch.
DataExchange): 136 distinct race warnings + SIGSEGV (exit 139) on unpatched master → 0 races,
clean exit, confirmed at both 8×25 and 10×200 thread/round configurations.