Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 276136 - Possible race condition in plugin model manager
Summary: Possible race condition in plugin model manager
Status: CLOSED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: PDE-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 275131 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-05-13 12:54 EDT by Aleksander Bandelj CLA
Modified: 2013-12-20 11:15 EST (History)
4 users (show)

See Also:


Attachments
Screenshot of duplicate bundles (48.57 KB, image/png)
2009-05-13 13:15 EDT, Aleksander Bandelj CLA
no flags Details
Target platform and other views (128.10 KB, image/png)
2009-05-14 04:29 EDT, Aleksander Bandelj CLA
no flags Details
Patch which clears fEntries table (1.59 KB, patch)
2009-05-19 14:32 EDT, Aleksander Bandelj CLA
no flags Details | Diff
My current race condition patch - for demonstration purposes only (3.24 KB, patch)
2009-12-16 11:46 EST, Aleksander Bandelj CLA
no flags Details | Diff
Working patch (2.77 KB, text/plain)
2013-03-08 09:11 EST, Aleksander Bandelj CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aleksander Bandelj CLA 2009-05-13 12:54:04 EDT
Build ID: I20090430-2300

Steps To Reproduce:
This happens only in some workspaces, but seems to be dependent on workspace content (starting with fresh workspace and importing leads to same result). Every bundle from target platform is listed twice and entries from PluginRegistry#findEntry have two bundle models with identical location and version. This causes bug 275131.
Comment 1 Chris Aniszczyk CLA 2009-05-13 12:55:07 EDT
There's a 'Target Platform State' view.

Can you post a screenshot of some duplicates? 
Comment 2 Aleksander Bandelj CLA 2009-05-13 13:15:34 EDT
Created attachment 135629 [details]
Screenshot of duplicate bundles
Comment 3 Aleksander Bandelj CLA 2009-05-13 13:23:50 EDT
Bundles are listed only once in target platform view but twice in other views (and bundle selection dialogs), see screenshot. In a particular workspace, every target platform I choose ends with duplicate bundles. I've also observed instances when loading of target platform works correctly, but I can't say what causes this. 

In other workspaces, everything is OK. 
Comment 4 Aleksander Bandelj CLA 2009-05-13 13:57:48 EDT
This is rather strange. It seems that in this particular workspace, content of host eclipse platform is added to the target platform, regardless of declared target platform contents. As long as target platform has at least one location declared, running eclipse platform bundles are added to it. This happens most of the time, sometimes target platform is loaded as specified.

So, now I see where duplicate bundles come from, but I have no clue how or why eclipse running platform is added to target ...

Comment 5 Darin Wright CLA 2009-05-13 14:06:57 EDT
What locations are specified in your active target definition?
Comment 6 Aleksander Bandelj CLA 2009-05-13 14:14:36 EDT
I have different eclipse installs for eclipse target platform location and running platform. But even if I have no eclipse install in my target platform definition, for example jdbc drivers only, I still get eclipse bundles

<target name="test">
<locations>
<location path="${workspace_loc}/../platform/jdbc/eclipse" type="Directory"/>
</locations>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
<nl>en_US</nl>
</environment>
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
</target>

Same with absolute path...

To complicate things further, it seems that running platform bundles are added to PDE only, not target platform. So running platform bundles are always visible in e.g Open Plugin Artifact view, but not in launch configuration. If I add eclipse target platform to target platform definition, I get duplicate bundles.

Comment 7 Chris Aniszczyk CLA 2009-05-13 14:25:03 EDT
Can you screenshot the Target Platform State view? It's a new view as of Eclipse 3.5 M7 :)

Are there link files here?

${workspace_loc}/../platform/jdbc/eclipse
Comment 8 Aleksander Bandelj CLA 2009-05-14 04:29:32 EDT
Created attachment 135755 [details]
Target platform and other views
Comment 9 Aleksander Bandelj CLA 2009-05-14 04:33:41 EDT
No link files, just plain directory. It's really strange, since I started from clean workspace and imported projects into it. Well, I imported preferences as well, but I imported exactly same preferences into several other workspaces and they show no such behaviour. I emphasize: same target definitions work OK in other workspaces. So, must be something with this workspace content. Any suggestions where to start debugging ?
Comment 10 Aleksander Bandelj CLA 2009-05-14 05:27:42 EDT
After debugging LoadTargetDefinitionJob, it seems that target platform is loaded OK. But dialogs which show duplicate bundles (and launch configuration dialog) get their bundle models from PluginModelManager [1], which stores old bundles. It seems that bundle models are stored PluginModelManager#fEntries, which isn't updated on PluginModelManager#resetState. So old bundles linger on ...

[1] PDECore.getDefault().getModelManager()
Comment 11 Aleksander Bandelj CLA 2009-05-14 05:41:20 EDT
Incremental update of PluginModelManager#fEntries (or #getEntryTable) in PluginModelManager#resetState seems brittle. Bundles from old target are removed and bundles from new target are added. But if #fEntries ends up in inconsistent/zombie state (maybe from some stored target in .plugins/org.eclipse.pde.core), then zombie plugins will linger there for lifetime of platform and wreak havoc with PDE tooling.

So, I would propose clearing #fEntries table or instantiating new PluginModelManager on target platform reload.
Comment 12 Aleksander Bandelj CLA 2009-05-14 06:07:34 EDT
After applying this change to HEAD, the zombie bundles are no more and the bug seems fixed. Not sure, however, if this is the right place to reset fEntries table.

  public class PluginModelManager implements IModelProviderListener {
***************
*** 118,123 ****
--- 117,124 ----
  
                // reset the state
                if ((e.getEventTypes() & IModelProviderEvent.TARGET_CHANGED) != 0) {
+                       fEntries = null;
+                       initializeTable();
                        Object newState = e.getEventSource();
                        if (newState instanceof PDEState) {
                                fState = (PDEState) newState;
Comment 13 Aleksander Bandelj CLA 2009-05-14 11:59:28 EDT
My guess as to why zombie bundles appeared: on problematic workspace, target platform restore on startup somehow didn't work in reliable manner. Or maybe saved state was wrong because of issues like bug 266935. 

So I had to reload platform on every startup. Target platform state was OK, but PDE state did also include zombie bundles from incomplete restore.

Comment 14 Aleksander Bandelj CLA 2009-05-19 13:11:58 EDT
Seems to be solved by patch to 266935. However, I still think that it would be a good idea to clean PluginModelManager#fEntries between target platform reloads.
Comment 15 Aleksander Bandelj CLA 2009-05-19 13:16:39 EDT
*** Bug 275131 has been marked as a duplicate of this bug. ***
Comment 16 Darin Wright CLA 2009-05-19 13:53:04 EDT
marking as a dup, since bug 266935 was root cause.

*** This bug has been marked as a duplicate of bug 266935 ***
Comment 17 Aleksander Bandelj CLA 2009-05-19 14:18:43 EDT
Sorry for wrong report, but I've just noticed duplicate bundles still appear when using patch from bug 266935. So, not a duplicate of bug 266935.
Comment 18 Aleksander Bandelj CLA 2009-05-19 14:32:30 EDT
Created attachment 136361 [details]
Patch which clears fEntries table

This patch seems to work but also needs work, just a working workaround ;)
Comment 19 Aleksander Bandelj CLA 2009-06-08 05:43:42 EDT
Seems to be fixed in 3.5RC4, probably because of fix to bug 277611.
Comment 20 Aleksander Bandelj CLA 2009-06-08 07:01:44 EDT
Duplicate bundles still appear, reopening.
Comment 21 Darin Wright CLA 2009-06-08 16:20:10 EDT
(In reply to comment #9)
> I emphasize: same target definitions work OK in
> other workspaces. So, must be something with this workspace content.

Is it still true that this is only a problem in one workspace?

The target definition you provided in comment#6 shows only one location, but the screen shot in comment#8 looks like it has a target editor with multiple locations. Are there multiple locations?
Comment 22 Aleksander Bandelj CLA 2009-06-09 05:31:07 EDT
Yes, only a problem in single workspace, but reproducible from this workspace (and maybe target platform contents). I've rebuilt this workspace from clean slate several times, always leading to this bug (and my patch as only working solution)

There are several locations but it also happened when I had single location. But single location was just an example.
Comment 23 Aleksander Bandelj CLA 2009-10-27 15:14:35 EDT
In 3.6M2, after manual cleanup of .metadata/.plugins/org.eclipse.pde.core/*.{target,workspace,extensions}  and major changes in my workspace and target platform this bug doesn't seem to appear anymore.
Comment 24 Aleksander Bandelj CLA 2009-12-14 12:56:00 EST
This bug still appears, sooner or later. Has something to do with stored platform state (clearing PDE target platform files fixes it temporarily) and reloading, but I don't have time to track it down at present moment. In absence of better solution, I am applying my patch to o.e.pde.core on every milestone release ...
Comment 25 Aleksander Bandelj CLA 2009-12-16 11:01:07 EST
Ok, I think I finally found it, it's a race condition which depends on workspace contents and size. PluginModelManager#initializeTable sometimes calls itself from same thread, so synchronized modifier doesn't order execution. Target platform state is mangled as result( you have two different model objects representing same bundles) which causes many other deeply mysterious bugs. I think one such call sequence begins with fWorkspaceManager.getPluginModels(), which then calls TargetPlatformHelper.getTargetVersionString which then calls PluginModelManager#initializeTable

Sample stack trace, note that line numbers in PluginModelManager don't correspond to head, since I have debugging statements in there:

java.lang.Exception: Initializing plugin table from thread 31
at org.eclipse.pde.internal.core.PluginModelManager.initializeTable(PluginModelManager.java:399)
at org.eclipse.pde.internal.core.PluginModelManager.getEntryTable(PluginModelManager.java:385)
at org.eclipse.pde.internal.core.PluginModelManager.findEntry(PluginModelManager.java:744)
at org.eclipse.pde.internal.core.PluginModelManager.findModel(PluginModelManager.java:768)
at org.eclipse.pde.core.plugin.PluginRegistry.findModel(PluginRegistry.java:64)
at org.eclipse.pde.internal.core.TargetPlatformHelper.getTargetVersionString(TargetPlatformHelper.java:310)
at org.eclipse.pde.internal.core.TargetPlatformHelper.getTargetVersion(TargetPlatformHelper.java:359)
at org.eclipse.pde.internal.core.TargetPlatformHelper.getSchemaVersionForTargetVersion(TargetPlatformHelper.java:372)
at org.eclipse.pde.internal.core.TargetPlatformHelper.getSchemaVersion(TargetPlatformHelper.java:393)
at org.eclipse.pde.internal.core.plugin.PluginHandler.processingInstruction(PluginHandler.java:110)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.processingInstruction(AbstractSAXParser.java:711)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.processingInstruction(XMLDTDValidator.java:1018)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:474)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
at org.eclipse.pde.internal.core.plugin.AbstractExtensionsModel.load(AbstractExtensionsModel.java:85)
at org.eclipse.pde.internal.core.WorkspaceModelManager.loadModel(WorkspaceModelManager.java:261)
at org.eclipse.pde.internal.core.WorkspacePluginModelManager.createModel(WorkspacePluginModelManager.java:73)
at org.eclipse.pde.internal.core.WorkspaceModelManager.initialize(WorkspaceModelManager.java:98)
at org.eclipse.pde.internal.core.WorkspacePluginModelManager.getPluginModels(WorkspacePluginModelManager.java:349)
at org.eclipse.pde.internal.core.PluginModelManager.initializeTable(PluginModelManager.java:434)
at org.eclipse.pde.internal.core.PluginModelManager.findModel(PluginModelManager.java:782)
at org.eclipse.pde.core.plugin.PluginRegistry.findModel(PluginRegistry.java:77)
at org.eclipse.pde.internal.core.RequiredPluginsInitializer.initialize(RequiredPluginsInitializer.java:31)
at org.eclipse.jdt.internal.core.JavaModelManager.initializeContainer(JavaModelManager.java:2642)
at org.eclipse.jdt.internal.core.JavaModelManager$11.run(JavaModelManager.java:2548)
at org.eclipse.jdt.internal.core.JavaModelManager.initializeAllContainers(JavaModelManager.java:2586)
at org.eclipse.jdt.internal.core.JavaModelManager.getClasspathContainer(JavaModelManager.java:1808)
at org.eclipse.jdt.core.JavaCore.getClasspathContainer(JavaCore.java:2667)
at org.eclipse.jdt.internal.core.JavaProject.resolveClasspath(JavaProject.java:2576)
at org.eclipse.jdt.internal.core.JavaProject.resolveClasspath(JavaProject.java:2677)
at org.eclipse.jdt.internal.core.JavaProject.getResolvedClasspath(JavaProject.java:1864)
at org.eclipse.jdt.internal.core.ExternalFoldersManager.refreshReferences(ExternalFoldersManager.java:268)
at org.eclipse.jdt.internal.core.DeltaProcessor.resourceChanged(DeltaProcessor.java:1890)
at org.eclipse.jdt.internal.core.DeltaProcessingState.resourceChanged(DeltaProcessingState.java:470)
at org.eclipse.core.internal.events.NotificationManager$2.run(NotificationManager.java:291)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:285)
at org.eclipse.core.internal.events.NotificationManager.handleEvent(NotificationManager.java:269)
at org.eclipse.core.internal.resources.Workspace.broadcastEvent(Workspace.java:319)
at org.eclipse.core.internal.resources.Resource.refreshLocal(Resource.java:1782)
at org.eclipse.ui.internal.ide.application.IDEWorkbenchAdvisor$3.runInWorkspace(IDEWorkbenchAdvisor.java:373)
at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Comment 26 Curtis Windatt CLA 2009-12-16 11:12:40 EST
Looking at the code, I agree that the synch block might not prevent all race conditions.  Will try and look at this.  Thanks for taking the time to debug.
Comment 27 Aleksander Bandelj CLA 2009-12-16 11:46:58 EST
Created attachment 154573 [details]
My current race condition patch - for demonstration purposes only
Comment 28 Aleksander Bandelj CLA 2013-03-08 09:11:38 EST
Created attachment 228140 [details]
Working patch

I've been applying this patch for two years. It's the only way to free my main workspace from duplicate bundles. It's not workspace corruption, it's its content :(
Comment 29 Aleksander Bandelj CLA 2013-12-20 11:15:55 EST
FWIW, it finally works at it should in 4.4M4 (but not yet in 4.3.1)