JDK-8080867 : Runtime.exec handle inheritance changes cause Ctrl+C regression on Windows
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8u45
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-05-19
  • Updated: 2015-06-08
  • Resolved: 2015-05-21
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

also:

java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Our customer reported a dangerous regression when using Ant to start background processes from a Windows command prompt, in which a child process that was started by a (now-completed) invocation of ant/Java get unexpectedly terminated when the command prompt is closed or receives a Ctrl+C. 

I can repro with a trivial invocation of Runtime.exec, which is showing a clear regression in behaviour between Java 1.7.0_45 to _65 (and is also broken in the same way on the latest 1.8.0_45). I also tried using ProcessBuilder with various inheritance options and wasn't able to work around it, so it seems there is now no way to safely exec a background child process in Java from a windows command prompt.

Very likely this was broken by the fix for either http://bugs.java.com/view_bug.do?bug_id=7147084 or http://bugs.java.com/view_bug.do?bug_id=8007454 (which both went into update 60). 

It's not obvious to me from the MSDN doc on CreateProcess https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 what the solution is, but the handle inheritance changes are by far the most likely culprit. I don't know whether setting the DETACHED_PROCESS process creation flag would help.

REGRESSION.  Last worked in version 7u75

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Open a Windows command prompt 

- use java.exe to execute a trivial java program that uses Runtime.exec to start a long-lived background process - doesn't make a difference whether it generates output (e.g. ping) or not (e.g. sleep); see sample program below

- after the Java process has terminated, the newly created child process (e.g. ping) naturally continues running as expected

- now press Ctrl+C (at the C:\> prompt), or close the parent command prompt window

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The background process should continue running unaffected (can use task manager to verify this) 
ACTUAL -
The background process terminates. 

This is a regression in behaviour - the child process continues to run fine with 1.7.0u45, but does not with u65

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Exec
{
	public static void main(String[] args) throws Exception
	{
		Runtime.getRuntime().exec(new String[]{"ping", "-n", "10000", "localhost"});
	}
}

---------- END SOURCE ----------


Comments
Received confirmation from the submitter: ----------------------------------------------------------------- On 6/8/2015 6:14 PM, ........... wrote: > Hi ......, thanks for taking the time to look at this. > > I've verified that the bug is fixed using 1.8.0_60-ea > > Cheers! > ........... ------------------------------------------
08-06-2015

Sent an email to the submitter: --------------------------------------------------------------------------------- Hi ..., Can you check with 8u60 ea and 9 ea builds and confirm back if the issue is still persisting? You can download the ea versions from: https://jdk8.java.net/download https://jdk9.java.net/download Thank You, .......... https://bugs.openjdk.java.net/browse/JDK-8080867 ---------------------------------------------------------------------------
08-06-2015