JDK-8041711 : (process) Process stream lost with bash background scripts (lnx)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7u51,8,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-04-23
  • Updated: 2020-04-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_minorUnresolved
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux mushroom 2.6.18-274.el5 #1 SMP Fri Jul 8 17:36:59 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
If exec is used to run a bash script that in turn runs something else in the background, the stdout/stderr from that command does not reliably make it back to the caller of exec.

Removing the & to not run the command in the background makes it work.

This shows up in Java 7 and 8, but worked in 6. The problem is with both stdout and stderr.


REGRESSION.  Last worked in version 6u43

ADDITIONAL REGRESSION INFORMATION: 
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run attached program against the echo_cmd.sh script. Data from script does not rerurn reliably.

Remove & from script. Functions as expected.

This works in Java 6 but fails on 7 and 8 (linux). Fails for both stdout and stderr.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
0: Out = 
0: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
1: Out = 
1: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
2: Out = 
2: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
3: Out = 
3: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
4: Out = 
4: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
5: Out = 
5: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
6: Out = 
6: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
7: Out = 
7: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
8: Out = 
8: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9
9: Out = 
9: Err = 
Hello0
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
Hello7
Hello8
Hello9

ACTUAL -
0: Out = 
0: Err = 
1: Out = 
1: Err = 
2: Out = 
2: Err = 
3: Out = 
3: Err = 
4: Out = 
4: Err = 
5: Out = 
5: Err = 
6: Out = 
6: Err = 
7: Out = 
7: Err = 
8: Out = 
8: Err = 
9: Out = 
9: Err =

REPRODUCIBILITY :
This bug can be reproduced always.

I've attached the sources to the bug report. Download all three files to local directory and run. (I can't reproduce on solaris) - Seen on linux.


CUSTOMER SUBMITTED WORKAROUND :
Cannot use bash backgrounding in this situation.


Comments
This is not a regression. In JDK6, if the first bash script prints something to stdout and/or stderr, then the result from the second (background) child process is sometimes missing. With the fix for JDK-6944584 in JDK 7 the child process's input/errorStream() were changed to get drained when the child process exits. To estimate the size of an array, InputStream.available() is used. This method appears to produce not quite accurate results in the described scenario.
02-03-2019

From http://docs.oracle.com/javase/7/docs/api/java/lang/Process.html : "The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, *daemon* processes, Win16/DOS processes on Microsoft Windows, or *shell scripts*. "
17-02-2015

Can reproduce okay, and verify that it is a regression since 6.
25-04-2014