Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 359485 - Indexer deadlocks in JUnit tests
Summary: Indexer deadlocks in JUnit tests
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-indexer (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: Project Inbox CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on: 359698 359851 376141
Blocks: 375601
  Show dependency tree
 
Reported: 2011-09-29 16:47 EDT by Andrew Gvozdev CLA
Modified: 2012-04-10 10:16 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Gvozdev CLA 2011-09-29 16:47:09 EDT
I am not able to finish cdt.ui unit tests ever. Here is relevant stack:

Thread [Worker-4] (Suspended)	
	ProjectPreferences(EclipsePreferences).getChild(String, Object, boolean) line: 400	<- blocked on 'this' instance of IEclipsePreferences
	ProjectPreferences(EclipsePreferences).internalNode(String, boolean, Object) line: 542	
	ProjectPreferences(EclipsePreferences).node(String) line: 670	
	IndexerPreferences.getProjectPreferences(IProject) line: 307	
	IndexerPreferences.addChangeListener(IProject, IEclipsePreferences$IPreferenceChangeListener) line: 351	
	PDOMManager.registerPreferenceListener(ICProject) line: 769	
	PDOMManager.registerIndexer(ICProject, IPDOMIndexer) line: 515	
	PDOMManager.createIndexer(ICProject, IProgressMonitor) line: 562	<-- Holds the lock on fUpdatePolicies
	PDOMSetupJob.run(IProgressMonitor) line: 58	
	Worker.run() line: 54	

Thread [main] (Suspended)	
	PDOMManager.getIndexer(ICProject) line: 522	<-- blocked on fUpdatePolicies
	PDOMManager.changeProject(ICProject, ITranslationUnit[], ITranslationUnit[], ITranslationUnit[]) line: 782	
	CModelListener.elementChanged(ElementChangedEvent) line: 70	
	CModelManager$1.run() line: 1101	
	SafeRunner.run(ISafeRunnable) line: 42	
	CModelManager.notifyListeners(ICElementDelta, int, IElementChangedListener[], int[], int) line: 1094	
	CModelManager.firePostChangeDelta(ICElementDelta, IElementChangedListener[], int[], int) line: 1051	
	CModelManager.fire(ICElementDelta, int) line: 1016	
	CModelManager.fire(int) line: 973	
	CModelManager.resourceChanged(IResourceChangeEvent) line: 892	
	NotificationManager$1.run() line: 291	
	SafeRunner.run(ISafeRunnable) line: 42	
	NotificationManager.notify(ResourceChangeListenerList$ListenerEntry[], IResourceChangeEvent, boolean) line: 285	
	NotificationManager.broadcastChanges(ElementTree, ResourceChangeEvent, boolean) line: 149	
	Workspace.broadcastPostChange() line: 395	
	Workspace.endOperation(ISchedulingRule, boolean, IProgressMonitor) line: 1530	
	Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor) line: 2353	
	ProjectPreferences.save() line: 628	
	ProjectPreferences(EclipsePreferences).flush() line: 353	<-- Holds lock 'this', instance of IEclipsePreferences
	ProjectPreferences.flush() line: 380	
	CProject.setOption(String, String) line: 313	
	FormatActionTest$FormatTestSetup.setUp() line: 60	
	TestSetup$1.protect() line: 22	
	TestResult.runProtected(Test, Protectable) line: 128	
	FormatActionTest$FormatTestSetup(TestSetup).run(TestResult) line: 27	
	SuiteMethod(JUnit38ClassRunner).run(RunNotifier) line: 83	
	JUnit4TestClassReference(JUnit4TestReference).run(TestExecution) line: 50	
	TestExecution.run(ITestReference[]) line: 38	
	RemotePluginTestRunner(RemoteTestRunner).runTests(String[], String, TestExecution) line: 467	
	RemotePluginTestRunner(RemoteTestRunner).runTests(TestExecution) line: 683	
	RemotePluginTestRunner(RemoteTestRunner).run() line: 390	
	RemotePluginTestRunner.main(String[]) line: 62	
	PlatformUITestHarness$1.run() line: 47	
	RunnableLock.run() line: 35	
	UISynchronizer(Synchronizer).runAsyncMessages(boolean) line: 135	
	Display.runAsyncMessages(boolean) line: 4140	
	Display.readAndDispatch() line: 3757	
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2696	
	Workbench.runUI() line: 2660	
	Workbench.access$4(Workbench) line: 2494	
	Workbench$7.run() line: 674	
	Realm.runWithDefault(Realm, Runnable) line: 332	
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 667	
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149	
	IDEApplication.start(IApplicationContext) line: 123	
	UITestApplication(NonUIThreadTestApplication).runApp(Object, IApplicationContext, String[]) line: 54	
	UITestApplication.runApp(Object, IApplicationContext, String[]) line: 41	
	UITestApplication(NonUIThreadTestApplication).start(IApplicationContext) line: 48	
	EclipseAppHandle.run(Object) line: 196	
	EclipseAppLauncher.runApplication(Object) line: 110	
	EclipseAppLauncher.start(Object) line: 79	
	EclipseStarter.run(Object) line: 344	
	EclipseStarter.run(String[], Runnable) line: 179	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	Method.invoke(Object, Object...) line: not available	
	Main.invokeFramework(String[], URL[]) line: 622	
	Main.basicRun(String[]) line: 577	
	Main.run(String[]) line: 1410	
	Main.main(String[]) line: 1386
Comment 1 Andrew Gvozdev CLA 2011-09-29 16:52:55 EDT
(In reply to comment #0)
> I am not able to finish cdt.ui unit tests ever. Here is relevant stack:
Note that the stack is actually for tag CDT_8_0 - CDT 8.0 final.
Comment 2 Marc-André Laperle CLA 2011-09-30 21:58:23 EDT
The method org.eclipse.core.internal.preferences.EclipsePreferences.flush()

is now synchronized in 3.7.1, this is why we are seeing a deadlock now.
Comment 3 Marc-André Laperle CLA 2011-09-30 23:53:23 EDT
From what I understand, even if a CProject is created without index (IPDOMManager.ID_NO_INDEXER) the PDOMSetupJob runs and gets a lock on fUpdatePolicies then preferences. Before that finishes, a call to setOption locks preferences then the changes to preferences triggers a call to getIndexer which locks fUpdatePolicies. I tried adding a bunch of joinIndexer calls right after creating a project in AddBlockCommentTest, FormatActionTest, RemoveBlockCommentTest, ShiftActionTest. But even doing that I get an occasional deadlock and it seems wrong to me to have to joinIndexer for projects configured with IPDOMManager.ID_NO_INDEXER.
Comment 4 Marc-André Laperle CLA 2011-10-01 00:05:47 EDT
See bug 351231 for synchronized change.
Comment 5 Martin Oberhuber CLA 2011-10-03 08:26:22 EDT
While it may be possible to find a workaround in CDT, I think the real problem is the new "synchronized" method in equinox.preferences. Due to Open Calls form inside the synchronized block, others may deadlock too.

I have filed bug 359698 asking Equinox to fix the regression.
Comment 6 Andrew Gvozdev CLA 2011-10-03 10:23:24 EDT
(In reply to comment #3)
> From what I understand, even if a CProject is created without index
> (IPDOMManager.ID_NO_INDEXER) the PDOMSetupJob runs
It sounds that we should avoid running the job if no indexer is assigned. Sounds like right thing to do even if we may want to wait out for the preferences bug to get fixed.
Comment 7 Markus Schorn CLA 2011-10-03 10:40:28 EDT
(In reply to comment #6)
I provided a workaround.
Comment 8 CDT Genie CLA 2011-10-03 11:23:02 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 359485: Workaround deadlock with preferences.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=2ac81668e38d623ebe7d5b9439a5dbd20a020790
Comment 9 CDT Genie CLA 2011-10-03 12:23:01 EDT
*** cdt git genie on behalf of Markus Schorn ***

    Bug 359485: Workaround deadlock with preferences.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=242b783c8c4d32d13409ce099c72126ec7d24648
Comment 10 DJ Houghton CLA 2011-10-06 10:33:16 EDT
What are the steps/locations to load and run the CDT test versions that showed this failure? I have a patch for the core that I'd like to test. Thanks.
Comment 11 Andrew Gvozdev CLA 2011-10-06 11:21:26 EDT
(In reply to comment #10)
> What are the steps/locations to load and run the CDT test versions that showed
> this failure? I have a patch for the core that I'd like to test. Thanks.
- Before you run the tests, I suggest to install CDT first from Indigo update site or download from http://download.eclipse.org/tools/cdt/builds/8.0.0/index.html (I recommend that). Our unit tests may have implicit dependencies which are hard to track. Not sure whether you may need gcc in your path, probably it's OK for cdt.ui not to have it. Install everything except "C++ Remote Launch" and "Target Communication Framework" not to pull some extra 3-rd party plugins.
- CDT repository is ssh://user@git.eclipse.org/gitroot/cdt/org.eclipse.cdt.git.
- Clone it, check out  tag CDT_8_0 and import core/org.eclipse.cdt.ui.tests project.
- Find ui/org.eclipse.cdt.ui.tests.text/TextTestSuite.java and Run/Debug as JUnit Plugin Test. Note that deadlock is happening intermittently, in this bug FormatActionTest is reported. For me, it locked up most often in testBugs test.
- Don't be too impatient, some tests may take some seconds to run but normally a test shouldn't take more than 30 sec.
Comment 12 DJ Houghton CLA 2011-10-06 12:47:04 EDT
Cool, thanks for the detailed steps. I am able to check out the tests and run them.
Comment 13 Andrew Gvozdev CLA 2012-02-04 14:47:22 EST
This was fixed, closing.
Comment 14 Markus Schorn CLA 2012-04-05 03:04:35 EDT
For platform 3.8 we still rely on the workaround. The workaround itself needs to be removed before closing this bug.
Comment 15 Markus Schorn CLA 2012-04-10 10:16:15 EDT
The workaround is not needed (I have tested it) with platform 3.7.2 or 3.8m6.
I have removed the workaround for 8.1 and on the 8.0.x stream post 8.0.2.

Note: The combination CDT 8.0.2 with platform 3.7.2 contains both the platform fix and the workaround which causes bug 375601.