Bug 314607 - [terminal][local] Launching a terminal also pops up the console view
Summary: [terminal][local] Launching a terminal also pops up the console view
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: Terminal (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 3.2 RC3   Edit
Assignee: Martin Oberhuber CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: polish
Depends on:
Blocks:
 
Reported: 2010-05-27 02:59 EDT by Mirko Raner CLA
Modified: 2010-11-16 07:56 EST (History)
2 users (show)

See Also:


Attachments
Patch to avoid Console allocation when IStreamMonitor already contains data during RuntimeProcess initialization (2.86 KB, patch)
2010-05-28 05:02 EDT, Mirko Raner CLA
mober.at+eclipse: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mirko Raner CLA 2010-05-27 02:59:42 EDT
Build Identifier: Helios RC2, DSDP/TM 3.2 RC2

From bug 309899, comment #18:

   P3: When creating a new terminal-launch and connecting it in a perspective
   that has no Console View open, the Console View pops up. This is 
   suspicious.

Also, if a Console view is present that view sometimes is brought to the top of the stack. I have seen this behavior on Mac OS as well, but it doesn't seem to happen all the time. There must be some additional factor that triggers this bug.


Reproducible: Sometimes
Comment 1 Mirko Raner CLA 2010-05-27 03:10:58 EDT
I get the following stack trace when it happens:

Daemon Thread [Thread-0] (Suspended (breakpoint at line 830 in WorkbenchPage))	
	WorkbenchPage.bringToTop(IWorkbenchPart) line: 830	
	ConsoleManager$ShowConsoleViewJob.runInUIThread(IProgressMonitor) line: 307	
	UIJob$1.run() line: 95	
	RunnableLock.run() line: 35	
	UISynchronizer(Synchronizer).runAsyncMessages(boolean) line: 134	
	Display.runAsyncMessages(boolean) line: 3549	
	Display.readAndDispatch() line: 3243	
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2416	
	Workbench.runUI() line: 2380	
	Workbench.access$4(Workbench) line: 2229	
	Workbench$5.run() line: 504	
	Realm.runWithDefault(Realm, Runnable) line: 332	
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 497	
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149	
	IDEApplication.start(IApplicationContext) line: 115	
	EclipseAppHandle.run(Object) line: 196	
	EclipseAppLauncher.runApplication(Object) line: 110	
	EclipseAppLauncher.start(Object) line: 79	
	EclipseStarter.run(Object) line: 369	
	EclipseStarter.run(String[], Runnable) line: 179	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
	Method.invoke(Object, Object...) line: 597	
	Main.invokeFramework(String[], URL[]) line: 619	
	Main.basicRun(String[]) line: 574	
	Main.run(String[]) line: 1406	
	Main.main(String[]) line: 1382
Comment 2 Mirko Raner CLA 2010-05-27 03:20:27 EDT
Hm, on closer inspection this stack trace doesn't help too much, because ShowConsoleViewJob is scheduled asynchronously. The more important question is who is scheduling it (and why). I'm trying another breakpoint at ConsoleManager.showConsoleView(IConsole)...
Comment 3 Martin Oberhuber CLA 2010-05-27 03:21:25 EDT
Since the ShowConsoleViewJob runs asynchronously, this backtrace does not help much. You'll need to set a breakpoint in the constructor of ShowConsoleViewJob to see who requests this job.
Comment 4 Mirko Raner CLA 2010-05-27 03:30:51 EDT
Great minds think alike :-)

This looks like it could be a race condition related to LocalTerminalProcess.resetStreamsProxy(); I'll look into this tomorrow.
Comment 5 Martin Oberhuber CLA 2010-05-27 05:25:58 EDT
Perhaps it's sufficient when you set the "Allocate Console" checkbox OFF on the Common Tab when creating the default Launch? I did this manually, and could not see a Console pop up.
Comment 6 Mirko Raner CLA 2010-05-28 02:42:52 EDT
All right, here's finally a stack trace that shows better how the Local Terminal Connector is involved in this (sure enough, as soon as you really want the bug to happen it stubbornly refused to show itself for quite a while):

Daemon Thread [Thread-0] (Suspended (entry into method showConsoleView in ConsoleManager))	
	ConsoleManager.showConsoleView(IConsole) line: 326	
	ProcessConsole(AbstractConsole).activate() line: 302	
	IOConsoleOutputStream.notifyParitioner(String) line: 248	
	IOConsoleOutputStream.encodedWrite(String) line: 240	
	IOConsoleOutputStream.write(String) line: 225	
	ProcessConsole$StreamListener.streamAppended(String, IStreamMonitor) line: 615	
	ProcessConsole$StreamListener.<init>(ProcessConsole, String, IStreamMonitor, IOConsoleOutputStream) line: 571	
	ProcessConsole.connect(IStreamMonitor, String, boolean) line: 516	
	ProcessConsole.connect(IStreamsProxy) line: 485	
	ConsoleColorProvider.connect(IProcess, IConsole) line: 42	
	ProcessConsole.<init>(IProcess, IConsoleColorProvider, String) line: 186	
	ProcessConsoleManager.launchChanged(ILaunch) line: 145	
	LaunchManager$LaunchNotifier.run() line: 452	
	SafeRunner.run(ISafeRunnable) line: 42	
	LaunchManager$LaunchNotifier.notify(ILaunch, int) line: 433	
	LaunchManager.fireUpdate(ILaunch, int) line: 995	
	Launch.fireChanged() line: 388	
	Launch.addProcess(IProcess) line: 351	
	LocalTerminalProcess(RuntimeProcess).<init>(ILaunch, Process, String, Map) line: 125	
	LocalTerminalProcess.<init>(ILaunch, Process, String, Map) line: 82	
	LocalTerminalProcessFactory.newProcess(ILaunch, Process, String, Map) line: 38	
	DebugPlugin.newProcess(ILaunch, Process, String, Map) line: 722	
	LocalTerminalLaunchDelegate.launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor) line: 199	
	LaunchConfiguration.launch(String, IProgressMonitor, boolean, boolean) line: 853	
	LaunchConfiguration.launch(String, IProgressMonitor, boolean) line: 702	
	LaunchConfiguration.launch(String, IProgressMonitor) line: 695	
	LocalTerminalConnector.connect(ITerminalControl) line: 212	
	TerminalConnector.connect(ITerminalControl) line: 159	
	VT100TerminalControl.connectTerminal() line: 318	
	TerminalView.onTerminalConnect() line: 292	
	TerminalView.newConnection(String) line: 331	
	TerminalView.onTerminalSettings() line: 324	
	TerminalActionSettings.run() line: 37	
	TerminalActionSettings(Action).runWithEvent(Event) line: 498	
	ActionContributionItem.handleWidgetSelection(Event, boolean) line: 584	
	ActionContributionItem.access$2(ActionContributionItem, Event, boolean) line: 501	
	ActionContributionItem$6.handleEvent(Event) line: 452	
	EventTable.sendEvent(Event) line: 84	
	Display.sendEvent(EventTable, Event) line: 3725	
	ToolItem(Widget).sendEvent(Event) line: 1333	
	ToolItem(Widget).sendEvent(int, Event, boolean) line: 1356	
	ToolItem(Widget).sendEvent(int, Event) line: 1341	
	ToolItem(Widget).notifyListeners(int, Event) line: 1155	
	Display.runDeferredEvents() line: 3585	
	Display.readAndDispatch() line: 3241	
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2416	
	Workbench.runUI() line: 2380	
	Workbench.access$4(Workbench) line: 2229	
	Workbench$5.run() line: 504	
	Realm.runWithDefault(Realm, Runnable) line: 332	
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 497	
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149	
	IDEApplication.start(IApplicationContext) line: 115	
	EclipseAppHandle.run(Object) line: 196	
	EclipseAppLauncher.runApplication(Object) line: 110	
	EclipseAppLauncher.start(Object) line: 79	
	EclipseStarter.run(Object) line: 369	
	EclipseStarter.run(String[], Runnable) line: 179	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
	Method.invoke(Object, Object...) line: 597	
	Main.invokeFramework(String[], URL[]) line: 619	
	Main.basicRun(String[]) line: 574	
	Main.run(String[]) line: 1406	
	Main.main(String[]) line: 1382
Comment 7 Mirko Raner CLA 2010-05-28 02:50:43 EDT
(In reply to comment #5)
> Perhaps it's sufficient when you set the "Allocate Console" checkbox OFF on the
> Common Tab when creating the default Launch? I did this manually, and could not
> see a Console pop up.

I suspect that that was more attributable to the fact that we're probably dealing with a race condition here, and you just got lucky. The "Allocate Console" option (as well as another non-UI option that also controls aspects of how local launches interact with a console) actually needs to be turned ON, and LocalTerminalConnector.java, line 206/207 actually contains code that programmatically sets those options. I'll double-check this code as part of my investigation.
Comment 8 Mirko Raner CLA 2010-05-28 05:02:51 EDT
Created attachment 170320 [details]
Patch to avoid Console allocation when IStreamMonitor already contains data during RuntimeProcess initialization

ProcessConsoleManager.launchChanged(ILaunch) will cause a Console to appear if the IStreamMonitor of the process already contains data at that point. The patch cuts the problematic code path at org.eclipse.debug.ui.console.ConsoleColorProvider.connect(IProcess, IConsole) (line 41). I also updated the javadoc documentation to explain this fix.

Unless there are other code paths that have a similar side effect the patch should fix the issue. I tried reproducing the problem for quite some time after adding the patch but it appears to be fixed.
Comment 9 Martin Oberhuber CLA 2010-05-28 12:03:56 EDT
Patch applied, tested, released > I20100528. 
Thanks!