eclipse.platform icon indicating copy to clipboard operation
eclipse.platform copied to clipboard

Launch View: "Terminate and Relaunch" sometimes does not relaunch all processes of a Launch Group

Open jukzi opened this issue 1 year ago • 1 comments

In the launch View selecting a running launch group and choosing "Terminate and Relaunch" from the contet menu sometimes fails to relaunch the whole group or some of the processes. image

After that the launch view shows two nodes for the launchgroup, both showing the same - terminated - PIDs: image

Reproducable with a simple Program like:

public class Main {
	public static void main(String[] args) {
		while (true) {}
	}
}

Create 2 launches for the Program (just create 1 and duplicate it). Create 1 launchgroup to start both launches. Set option "adopt if runing" image

"run" the launch group, image

"Terminate and Relaunch" the launch group. Sometimes it is not fully relaunched: image

I have only seen it failing when option "adopt if runing" was used.

jukzi avatar Apr 17 '24 07:04 jukzi

It's a race condition:

GroupLaunchElement.adoptIfRunning was introduced to:

"allows to skip launching that configuration in case it is already running, launched either manually or by another group. This allows to prevent duplicate launches for certain configurations."

TerminateAndRelaunchAction first terminates the processes

Thread [Worker-17: Execute Debug Command] (Suspended)	
	owns: HashMap<K,V>  (id=561)	
	ProcessImpl.destroy() line: 607	
	RuntimeProcess.terminate() line: 265	
	Launch.terminate() line: 287	
	GroupLaunch.terminate() line: 155	
	TerminateCommand.execute(Object) line: 35	
	TerminateCommand(ForEachCommand).doExecute(Object[], IProgressMonitor, IRequest) line: 36	
	AbstractDebugCommand$1.run(IProgressMonitor) line: 215	
	Worker.run() line: 63	

And later uses org.eclipse.debug.core.model.RuntimeProcess.fTerminated to identify if the launch is already/still running

But that flag is only set asynchronous in org.eclipse.debug.core.model.RuntimeProcess.ProcessMonitorThread after the ProcessMonitor has terminated:

Daemon Thread [Process monitor for PID 22980 Main] (Suspended (breakpoint at line 334 in RuntimeProcess))	
	RuntimeProcess.terminated() line: 334	
	RuntimeProcess$ProcessMonitorThread.run() line: 516	

solution: synchronously remember thread is terminated after terminating it

jukzi avatar May 17 '24 07:05 jukzi