Fix race condition in AbstractReconciler causing test timeout #2708 #3454
  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
AbstractReconciler.BackgroundWorker.reset()causing intermittent test timeoutsProblem
The test
FastAbstractReconcilerTest#testReplacingDocumentWhenClean()was randomly failing on macOS (and other platforms) with a timeout error. The test expects the reconciler to complete within 5 seconds, but the reconciler thread never executed theprocess()method that would trigger the test's barrier synchronization.Root Cause
The race condition occurred due to improper ordering of operations in the
BackgroundWorker.reset()method. The code uses two separate locks:BackgroundWorkerinstance lock (forfIsDirtyandfReset)fDirtyRegionQueuelock (for notifications andwaitFinish)Old sequence:
fIsDirty=trueandfReset=true(under BackgroundWorker lock)fDirtyRegionQueue← Thread could wake up here!informNotFinished()→aboutToWork()aboutToWork()callssignalWaitForFinish()which setswaitFinish=trueThe reconciler thread could wake up from the notification in step 2 before
waitFinishwas set to true in step 4, causing it to enter a full delay period (fDelaymilliseconds) instead of processing immediately.Solution
Move the
informNotFinished()call to after setting the flags but before the final queue notification:New sequence:
fIsDirty=trueandfReset=true(under BackgroundWorker lock)informNotFinished()→aboutToWork()→signalWaitForFinish()signalWaitForFinish()setswaitFinish=trueand notifies queuenotifyAll()on queue (redundant but harmless)This ensures that when the reconciler thread wakes up, both
fIsDirtyandwaitFinishare already properly set, eliminating the race condition.Testing
mvn clean compile -Pbuild-individual-bundlesFastAbstractReconcilerTest.testReplacingDocumentWhenCleanRelated Issues
Fixes #2708
🤖 Generated with Claude Code