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

Bug 153737

Summary: [Progress] Modal dialogs deadlock during launching an Eclipse app
Product: [Eclipse Project] Platform Reporter: Alexei Alexandrov <alexei.alexandrov>
Component: UIAssignee: Tod Creasey <Tod_Creasey>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: baumanbr, darin.eclipse, public, wassim.melhem
Version: 3.2   
Target Milestone: 3.3 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 160745, 167134    
Bug Blocks:    
Attachments:
Description Flags
The problem screenshot none

Description Alexei Alexandrov CLA 2006-08-14 05:19:19 EDT
The attached picture demonstrates the problem. I have a plugin and launch configuration for it. I have set the "Clear workspace before launching" and "Ask for confirmation before cleaning" check boxes. Sometimes when I launch the configuration a deadlock happens: Launching progress dialog appears in front of the "Do you really want to clear the workspace" message box and waits for user's answer. The only way to go ahead is to press "Run in background" - in this case I get a chance to answer. If I press "Cancel" instead, it will deadlock completely.

P.S. "Build automatically" mode must be on to reproduce the problem.
Comment 1 Alexei Alexandrov CLA 2006-08-14 05:20:02 EDT
Created attachment 47833 [details]
The problem screenshot
Comment 2 Darin Wright CLA 2006-08-14 07:26:33 EDT
This type of launch is from PDE.
Comment 3 Tod Creasey CLA 2006-10-04 09:40:29 EDT
This is actually a platform issue - we should not be opening the user job dialog when there is a dialog already open.
Comment 4 Tod Creasey CLA 2006-10-04 09:44:19 EDT
Brian are you opening this dialog on the same shell as the debug dialog? if so then our API doesn't block if it is on the same shell - we should rethink that one. 
Comment 5 Brian Bauman CLA 2006-10-04 10:44:39 EDT
I am not sure which shell we end up opening against (we might find the shell incorrectly).  Here is the code we use to get the shell:

Display display = Display.getCurrent();
if (display == null) 
	display = Display.getDefault();
display.getActiveShell()
Comment 6 Brian Bauman CLA 2006-10-04 11:57:40 EDT
Darin, just wanted to give you a heads up as we discussed this issue.

I believe the launch dialog box is closed before Debug schedules the job.  If this is the case, I believe PDE (with the code above) would get the main workbench shell.  

Debug uses the following lines of code to get the shell to pass into the .showInDialog function.

IWorkbench workbench = DebugUIPlugin.getDefault().getWorkbench();
workbench.getActiveWorkbenchWindow().getShell()

It would not surprise me if both of them use the same main workbench shell.  If this were the case, we might expect behavior similar to this bug report, right?
Comment 7 Tod Creasey CLA 2006-10-06 11:17:56 EDT
BTW it is a lot safer to use something like the following (this is from ProgressManagerUtil)

	IWorkbenchWindow window = PlatformUI.getWorkbench()
				.getActiveWorkbenchWindow();
		if (window == null) {
			IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
					.getWorkbenchWindows();
			if (windows.length > 0)
				return windows[0].getShell();
		} else
			return window.getShell();

The problem with getActiveShell is that you can grab a lot of potential shells. If the active shell is closed on you you might lose the dialog or you may get inconsistent parents.
Comment 8 Tod Creasey CLA 2006-10-10 16:00:44 EDT
*** Bug 109120 has been marked as a duplicate of this bug. ***
Comment 9 Tod Creasey CLA 2006-10-12 16:19:33 EDT
Display display = Display.getCurrent();
if (display == null) 
        display = Display.getDefault();
display.getActiveShell()

is frequently different from 

DebugUIPlugin.getDefault().getWorkbench();
workbench.getActiveWorkbenchWindow().getShell()

shells can be used for content assist, tooltips, animations etc.

Where is the code where you call getActiveShell()?
Comment 10 Brian Bauman CLA 2006-10-12 18:18:36 EDT
We call it when launching if we need to display a dialog box.  The Debug Launching Dialog is already closed, so the active Shell should be the workbench window (as far as I believe).  

So it would be safer for PDE to do something similar to comment 7 when it needs a Shell upon which to open a dialog during the launching process, right?
Comment 11 Tod Creasey CLA 2006-10-13 07:52:12 EDT
As I said the active shell could be different becuase of a user action (i.e. if you have animations on the animated shell could be the active one).

Code like comment 7 is much safer - see Bug 160745
Comment 12 Tod Creasey CLA 2006-12-07 14:24:05 EST
If 167134 is implemented this will no longer be an issue
Comment 13 Tod Creasey CLA 2007-03-02 12:18:11 EST
Bug 167134 has cleared this up.
Comment 14 Tod Creasey CLA 2007-03-20 09:34:01 EDT
Verified in I20070319-1005