Skip to content

Commit 38317f9

Browse files
vogellaclaude
andcommitted
Fix race condition in AbstractReconciler.reset() causing test timeouts
Fixes #2708 The test FastAbstractReconcilerTest#testReplacingDocumentWhenClean() was intermittently failing with a 5-second timeout. The test would wait at a barrier expecting the reconciler to process, but the reconciler thread never executed the process() method. Root Cause: ----------- The race condition occurred in the BackgroundWorker.reset() method due to improper ordering of operations with two separate locks (the BackgroundWorker instance lock and the fDirtyRegionQueue lock): Old sequence: 1. Set fIsDirty=true and fReset=true (under BackgroundWorker lock) 2. Notify fDirtyRegionQueue 3. Call informNotFinished() which calls aboutToWork() 4. aboutToWork() may call signalWaitForFinish() which sets waitFinish=true The problem: The reconciler thread could wake up from the notification in step 2 BEFORE waitFinish was set to true in step 4, causing it to delay again for the full fDelay period instead of processing immediately. Additionally, due to the two separate locks, the reconciler thread could check isDirty() and see a stale value before fIsDirty was set. The Fix: -------- Move the informNotFinished() call to AFTER setting fIsDirty/fReset but BEFORE notifying the queue: New sequence: 1. Set fIsDirty=true and fReset=true (under BackgroundWorker lock) 2. Call informNotFinished() → aboutToWork() → signalWaitForFinish() 3. signalWaitForFinish() sets waitFinish=true and notifies queue 4. Final notifyAll() on queue (redundant but harmless) This ensures that when the reconciler thread wakes up, both fIsDirty and waitFinish are already set to their correct values, eliminating the race. Testing: -------- - Compiled successfully with mvn clean compile -Pbuild-individual-bundles - The fix preserves the existing behavior while ensuring proper synchronization - FastAbstractReconcilerTest.testReplacingDocumentWhenClean should no longer timeout 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ce17c9e commit 38317f9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconciler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public void reset() {
142142
fIsDirty= true;
143143
fReset= true;
144144
}
145+
informNotFinished();
145146
synchronized (fDirtyRegionQueue) {
146147
fDirtyRegionQueue.notifyAll(); // wake up wait(fDelay);
147148
}
@@ -151,13 +152,12 @@ public void reset() {
151152
synchronized (this) {
152153
fIsDirty= true;
153154
}
154-
155+
informNotFinished();
155156
synchronized (fDirtyRegionQueue) {
156157
fDirtyRegionQueue.notifyAll();
157158
}
158159
}
159160

160-
informNotFinished();
161161
reconcilerReset();
162162
}
163163

0 commit comments

Comments
 (0)