Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 335910

Summary: SynchronizableDocument causes deadlock by firing events inside of a lock
Product: [Eclipse Project] Platform Reporter: Kevan Holdaway <kholdaway>
Component: CompareAssignee: Platform-Compare-Inbox <platform-compare-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: thatnitind
Version: 3.6.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Kevan Holdaway CLA 2011-01-31 17:00:13 EST
Build Identifier: M20110112-0800

Our product add their own positions to the documents of open editors.  We use the standard eclipse org.eclipse.jface.text.IDocument.addPosition(String, Position) and org.eclipse.jface.text.IDocument.removePosition(String, Position) methods.

SynchronizableDocument fires events inside of the same lock it uses for addPosition/removePosition.  This can cause a deadlock.  Firing events in a lock is poor design as it puts an expectation on clients who handle the code.

Here is a sample stack trace found in a deadlock we experienced:
org/eclipse/jface/text/AbstractDocument.fireRewriteSessionChanged(Bytecode PC:50)
org/eclipse/jface/text/AbstractDocument.stopRewriteSession(Bytecode PC:87)
org/eclipse/core/internal/filebuffers/SynchronizableDocument.stopRewriteSession(Bytecode PC:21)

Note the code for stopRewriteSession:
	public void stopRewriteSession(DocumentRewriteSession session) {
		Object lockObject= getLockObject();
		if (lockObject == null) {
			super.stopRewriteSession(session);
			return;
		}
		synchronized (lockObject) {
			super.stopRewriteSession(session);
		}
	}

It makes the call to super.stopRewriteSession inside of the synchronized block.  This caused our product a deadlock.  

Reproducible: Sometimes
Comment 1 Lars Vogel CLA 2019-09-24 13:58:02 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 2 Eclipse Genie CLA 2021-10-31 18:56:27 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.