Skip to content

Commit 44d012c

Browse files
fedejeanneCopilot
andcommitted
Fix random failing testBug546710_ConsoleCreationRaceCondition #596
- Cancel all instances of ConsoleCreationJob for a given process when removing a launch. - Skip the creation of a console for a launch that has been canceled already. - Adapt assertion in test (it was checking the wrong console) Fixes #596 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent afeaa45 commit 44d012c

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ProcessConsoleManagerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,6 @@ public void testBug546710_ConsoleCreationRaceCondition(TestInfo testInfo) throws
148148
removeAction.run();
149149
TestUtil.waitForJobs(testInfo.getDisplayName(), ProcessConsoleManager.class, 0, 10000);
150150
assertNull(processConsoleManager.getConsole(process1), "First console not removed.");
151-
assertNull(processConsoleManager.getConsole(process1), "Second console not removed.");
151+
assertNull(processConsoleManager.getConsole(process2), "Second console not removed.");
152152
}
153153
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsoleManager.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ protected IStatus run(IProgressMonitor monitor) {
6969
if (monitor.isCanceled() || getConsoleDocument(process) != null) {
7070
return Status.CANCEL_STATUS;
7171
}
72+
// If a launch is removed the associated console is removed too. It can happen
73+
// that the launch is removed even before the console could be created.
74+
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=546710#c13
75+
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
76+
if (!launchManager.isRegistered(launch)) {
77+
return Status.CANCEL_STATUS;
78+
}
7279
IConsoleColorProvider colorProvider = getColorProvider(process.getAttribute(IProcess.ATTR_PROCESS_TYPE));
7380
String encoding = launch.getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING);
7481
ProcessConsole pc = new ProcessConsole(process, colorProvider, encoding);
@@ -77,10 +84,8 @@ protected IStatus run(IProgressMonitor monitor) {
7784
// add new console to console manager.
7885
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { pc });
7986

80-
// If a launch is removed the associated console is removed too. It can happen
81-
// that the launch is removed even before the console could be created.
82-
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=546710#c13
83-
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
87+
// Check again: the launch may have been removed while the console was being
88+
// created (race between console creation and launch removal).
8489
if (!launchManager.isRegistered(launch)) {
8590
removeLaunch(launch);
8691
}
@@ -139,6 +144,13 @@ public void launchRemoved(ILaunch launch) {
139144

140145
protected void removeLaunch(ILaunch launch) {
141146
for (IProcess process : launch.getProcesses()) {
147+
// Cancel any pending ConsoleCreation jobs for this process to prevent
148+
// creating a console for an already-removed launch.
149+
for (Job job : Job.getJobManager().find(process)) {
150+
if (job instanceof ConsoleCreation) {
151+
job.cancel();
152+
}
153+
}
142154
removeProcess(process);
143155
}
144156
if (fProcesses != null) {

0 commit comments

Comments
 (0)