Bug 481830 - [DiaGen] Initializing GMF Preferences from the Bundle's Activator may cause Deadlocks
Summary: [DiaGen] Initializing GMF Preferences from the Bundle's Activator may cause D...
Status: NEW
Alias: None
Product: Papyrus
Classification: Modeling
Component: Diagram (show other bugs)
Version: 1.1.0   Edit
Hardware: All All
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: Confirmed
Keywords:
Depends on:
Blocks: 511069
  Show dependency tree
 
Reported: 2015-11-10 08:07 EST by Camille Letavernier CLA
Modified: 2019-03-08 03:30 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Camille Letavernier CLA 2015-11-10 08:07:04 EST
All diagrams call the following snippet in their Activator#start method:

> CustomDiagramPreferenceInitializer diagramPreferenceInitializer = new CustomDiagramPreferenceInitializer();
> diagramPreferenceInitializer.initializeDefaultPreferences();

This eventually leads to the initialization of the GMF Appearance preference page, which uses a Display.syncExec() to define a Font.

Since the Properties View Configuration can be initialized in a Worker thread, the following steps typically happen when a generated Papyrus Diagram also declares a Properties View configuration:

- UI: Open the PropertiesView preference pages
- UI: PropertiesView's Activator#start in the UI Thread
-- UI: Starts a background Job to load properties view configurations and keep going
--- Worker: The background Job starts contributing plug-ins (e.g. Sequence Diagram) in a Worker Thread
--- Worker: SequenceDiagram initializes its preferences
--- Worker: The preferences eventually delegate to GMF's Appearance PreferencePage, which results in Display.syncExec()
-- UI: Waits for the PropertiesView configurations to be loaded to display the preference pages

So we have a deadlock between the Diagram's Activator waiting for the UI Thread, and the UI Preference Pages waiting for the Worker Thread to finish loading the properties view configurations

In general, it seems very dangerous to synchronously jump to another thread during the activation of a bundle (Directly or indirectly). These calls to initializeDefaultPreferences() should be either:

- Done asynchronously (e.g. Display.asyncExec() or a Job) to avoid blocking Activator#start
- Done somewhere else (Not in Activator#start, but rather when these preferences are actually required)

Since these methods are generated, they affect all diagrams, but are especially visible for the Diagrams that contribute Properties View configurations, since Properties View Configurations are loaded in a background (non-UI) job
Comment 1 Christian Damus CLA 2016-01-21 08:58:43 EST
This is now blocking my execution of the Papyrus All Tests suite in my Neon API refactorings, because now the OSGi class loader is deadlocking at start-up every time, on activation of the Sequence Diagram plug-in triggered by loading a properties constraint class.

These properties constraints are generally pretty simple algorithms and don't, I think, need to trigger lazy bundle activation.  Happily, most constraints are already partitioned into separate packages, which makes it easy to exclude them from the lazy activation rule.  It just needs this one constraint in the Sequence Diagram to be moved into its own package (it's currently in the utils package, which probably also doesn't need to trigger bundle activation, but I don't want to risk that).

Anyways, I have a fix in hand, so I'll take this bug.
Comment 2 Eclipse Genie CLA 2016-01-21 08:59:43 EST
New Gerrit change created: https://git.eclipse.org/r/64875
Comment 4 Christian Damus CLA 2016-01-22 09:15:48 EST
Unassigning this bug, as the Gerrit patch relieves some cases of deadlocks (especially in test execution) but doesn't address the root problem of bundle activators doing stuff synchronously on the UI thread.