Skip to content

Fix LcmMetaDataCache race condition on static Flid counter#373

Merged
myieye merged 1 commit intomasterfrom
fix-LcmMetaDataCache-race-condition
May 6, 2026
Merged

Fix LcmMetaDataCache race condition on static Flid counter#373
myieye merged 1 commit intomasterfrom
fix-LcmMetaDataCache-race-condition

Conversation

@myieye
Copy link
Copy Markdown
Contributor

@myieye myieye commented May 5, 2026

Somewhat similar to a previous race condition I fixed in #371.

This constructor resets a static "Flid counter", so when multiple caches are initialized in parallel our tests can stumble over duplicate Flid's in the same cache, which I think resulted in this exception:

---- SIL.LCModel.LcmInvalidFieldException : Fieldname 'Affixes' does not exist. Consider using a decorator or review the fieldname for typos.
Stack Trace:
at FwDataMiniLcmBridge.Api.FwDataMiniLcmApi.CreateEntry(Entry entry, CreateEntryOptions options) in D:\a\languageforge-lexbox\languageforge-lexbox\backend\FwLite\FwDataMiniLcmBridge\Api\FwDataMiniLcmApi.cs:line 1009
at FwLiteProjectSync.Tests.EntrySyncTestsBase.CanSyncRandomEntries(Nullable1 roundTripApiType) in D:\a\languageforge-lexbox\languageforge-lexbox\backend\FwLite\FwLiteProjectSync.Tests\EntrySyncTests.cs:line 194 --- End of stack trace from previous location --- ----- Inner Stack Trace ----- at SIL.LCModel.Infrastructure.Impl.LcmMetaDataCache.GetFieldId2(Int32 clid, String fieldName, Boolean includeBaseClasses) at SIL.LCModel.DomainServices.VirtualOrderingServices.CheckParentAndGetFieldName(ICmObject parent, Int32 flid) at SIL.LCModel.DomainServices.VirtualOrderingServices.GetOrderedValue(ICmObject parent, Int32 flid, IEnumerable1 unmodifiedSeq)
at SIL.LCModel.DomainServices.VirtualOrderingServices.GetOrderedValue[T](ICmObject parent, Int32 flid, IEnumerable1 unmodifiedSeq) at SIL.LCModel.DomainImpl.LexEntry.get_VisibleComplexFormBackRefs() at SIL.LCModel.DomainImpl.LexEntryRef.UpdateComplexFormEntryBackRefs(ICmObject thingAddedOrRemoved, Boolean fAdded) at SIL.LCModel.DomainImpl.LexEntryRef.AddObjectSideEffectsInternal(AddObjectEventArgs e) at SIL.LCModel.DomainImpl.CmObject.SIL.LCModel.ICmObjectInternal.AddObjectSideEffects(AddObjectEventArgs e) at SIL.LCModel.DomainImpl.LcmList1.AddObject(AddObjectEventArgs args)
at SIL.LCModel.DomainImpl.LcmReferenceSequence1.AddObject(AddObjectEventArgs args) at SIL.LCModel.DomainImpl.LcmList1.Add(T obj)
at SIL.LCModel.DomainImpl.LexEntry.AddComponent(ICmObject other)
at FwDataMiniLcmBridge.Api.FwDataMiniLcmApi.InsertComplexFormComponent(ILexEntry lexComplexForm, ICmObject lexComponent, BetweenPosition1 between) in D:\a\languageforge-lexbox\languageforge-lexbox\backend\FwLite\FwDataMiniLcmBridge\Api\FwDataMiniLcmApi.cs:line 1112 at FwDataMiniLcmBridge.Api.FwDataMiniLcmApi.AddComplexFormComponent(ILexEntry lexComplexForm, ComplexFormComponent component, BetweenPosition1 between) in D:\a\languageforge-lexbox\languageforge-lexbox\backend\FwLite\FwDataMiniLcmBridge\Api\FwDataMiniLcmApi.cs:line 1096
at FwDataMiniLcmBridge.Api.FwDataMiniLcmApi.<>c__DisplayClass125_0.b__0() in D:\a\languageforge-lexbox\languageforge-lexbox\backend\FwLite\FwDataMiniLcmBridge\Api\FwDataMiniLcmApi.cs:line 996
at SIL.LCModel.Infrastructure.UndoableUnitOfWorkHelper.Do(String undoText, String redoText, IActionHandler actionHandler, Action task)
...


This change is Reviewable

@myieye myieye added the 🟩Low Low-priority PR label May 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

LCM Tests

    16 files  ±0      16 suites  ±0   2m 44s ⏱️ -12s
 2 858 tests ±0   2 838 ✅ ±0   20 💤 ±0  0 ❌ ±0 
11 380 runs  ±0  11 212 ✅ ±0  168 💤 ±0  0 ❌ ±0 

Results for commit 3a52a99. ± Comparison against base commit b87d9f9.

@myieye
Copy link
Copy Markdown
Contributor Author

myieye commented May 6, 2026

We just ran into another exception that would presumably be fixed by this PR:
sillsdev/languageforge-lexbox#2252 (comment)

Copy link
Copy Markdown
Contributor

@rmunn rmunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like with #371, the added performance cost of locking once per constructor shouldn't be noticeable in FieldWorks where simultaneous construction pretty much never happens anyway. But it will certainly make the FieldWorks Lite tests (which create and destroy a lot of FW projects) more reliable when they're run in parallel. LGTM.

@myieye myieye merged commit 66da667 into master May 6, 2026
4 checks passed
@myieye myieye deleted the fix-LcmMetaDataCache-race-condition branch May 6, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🟩Low Low-priority PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants