From c9eee479b4c714509e1b006063a4cbdaeed9cdc4 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Fri, 12 Oct 2018 13:09:43 -0400 Subject: [PATCH] Bug 540085 - Deadlock in ToolChainManager init - modify ContainerGCCToolChainProvider.init so that the CBuildConfigurationManager.recheckConfigs() call is done within a separate job so the init() call will return without causing deadlock - do the same for ContainerTargetTypeProvider - modify CBuildConfigurationManager initProviders() method to be synchronized Change-Id: I4ca9371fb340887233872b6d315621a24450fb2b --- .../build/CBuildConfigurationManager.java | 2 +- .../launcher/ContainerTargetTypeProvider.java | 25 +++++++++++++----- .../ContainerGCCToolChainProvider.java | 26 ++++++++++++++----- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java index eaa35c8ec4f..f46b06675a9 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/build/CBuildConfigurationManager.java @@ -101,7 +101,7 @@ public class CBuildConfigurationManager implements ICBuildConfigurationManager, ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); } - private void initProviders() { + private synchronized void initProviders() { if (providers == null) { providers = new HashMap<>(); diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java index 297359f6762..83752285352 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java @@ -123,12 +123,25 @@ public class ContainerTargetTypeProvider DockerConnectionManager.getInstance() .addConnectionManagerListener(this); - // call the recheckConfigs method in case any disabled targets are now - // ok - ICBuildConfigurationManager mgr = CCorePlugin - .getService(ICBuildConfigurationManager.class); - ICBuildConfigurationManager2 manager = (ICBuildConfigurationManager2) mgr; - manager.recheckConfigs(); + // re-check configs in case an enabled Connection has made old configs + // valid again do this in a separate job to prevent a possible + // deadlock trying to get the lock on the CBuildConfigurationManager + // "configs" map (Bug 540085) + Job checkConfigs = new Job("Check configs") { //$NON-NLS-1$ + @Override + protected IStatus run(IProgressMonitor monitor) { + // call the recheckConfigs method in case any disabled targets + // are now + // ok + ICBuildConfigurationManager mgr = CCorePlugin + .getService(ICBuildConfigurationManager.class); + ICBuildConfigurationManager2 cbuildmanager = (ICBuildConfigurationManager2) mgr; + cbuildmanager.recheckConfigs(); + return Status.OK_STATUS; + } + }; + checkConfigs.setUser(true); + checkConfigs.schedule(); try { launchbarManager.setActiveLaunchTarget(defaultTarget); diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java index defb52a92a8..9bcad227db2 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java @@ -98,13 +98,25 @@ public class ContainerGCCToolChainProvider DockerConnectionManager.getInstance() .addConnectionManagerListener(this); - // call the recheckConfigs method in case any disabled targets are now - // ok - ICBuildConfigurationManager mgr = CCorePlugin - .getService(ICBuildConfigurationManager.class); - ICBuildConfigurationManager2 cbuildmanager = (ICBuildConfigurationManager2) mgr; - cbuildmanager.recheckConfigs(); - + // re-check configs in case an enabled Connection has made old configs + // valid again do this in a separate job to prevent a possible + // deadlock trying to get the lock on the CBuildConfigurationManager + // "configs" map (Bug 540085) + Job checkConfigs = new Job("Check configs") { //$NON-NLS-1$ + @Override + protected IStatus run(IProgressMonitor monitor) { + // call the recheckConfigs method in case any disabled targets + // are now + // ok + ICBuildConfigurationManager mgr = CCorePlugin + .getService(ICBuildConfigurationManager.class); + ICBuildConfigurationManager2 cbuildmanager = (ICBuildConfigurationManager2) mgr; + cbuildmanager.recheckConfigs(); + return Status.OK_STATUS; + } + }; + checkConfigs.setUser(true); + checkConfigs.schedule(); } @Override