From gwk@mscsoftware.com  Fri Oct 11 03:58:19 2002
Return-Path: <gwk@mscsoftware.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9BA6637B401
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 11 Oct 2002 03:58:19 -0700 (PDT)
Received: from draco.macsch.com (ns1.mscsoftware.com [192.207.69.10])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 132AD43EAC
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 11 Oct 2002 03:58:19 -0700 (PDT)
	(envelope-from gwk@mscsoftware.com)
Received: from mailmuc.muc.eu.mscsoftware.com (mailmuc.muc.macsch.com [161.34.37.20])
	by draco.macsch.com (8.9.3/8.9.3) with ESMTP id DAA20893
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 11 Oct 2002 03:57:59 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1])
	by mailmuc.muc.eu.mscsoftware.com (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id g9BAsJo08424;
	Fri, 11 Oct 2002 12:54:19 +0200
Received: from hunter.muc.macsch.com
	by mailmuc.muc.eu.mscsoftware.com (AvMailGate-2.0.1.2) id 08320-52C65C00;
	Fri, 11 Oct 2002 12:53:37 +0200
Received: from hunter.muc.macsch.com (localhost.muc.macsch.com [127.0.0.1])
	by hunter.muc.macsch.com (8.12.3/8.12.3) with ESMTP id g9BAvZE2003867;
	Fri, 11 Oct 2002 12:57:35 +0200 (CEST)
	(envelope-from gwk@hunter.muc.macsch.com)
Received: (from gwk@localhost)
	by hunter.muc.macsch.com (8.12.3/8.12.3/Submit) id g9BAvZxV003866;
	Fri, 11 Oct 2002 12:57:35 +0200 (CEST)
Message-Id: <200210111057.g9BAvZxV003866@hunter.muc.macsch.com>
Date: Fri, 11 Oct 2002 12:57:35 +0200 (CEST)
From: "Georg-W. Koltermann" <Georg.Koltermann@mscsoftware.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Georg.Koltermann@mscsoftware.com
Subject: writing from JAVA to a pipe sometimes hangs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         43924
>Category:       java
>Synopsis:       writing from JAVA to a pipe sometimes hangs
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    glewis
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 11 04:00:13 PDT 2002
>Closed-Date:    Thu Aug 18 05:07:01 UTC 2011
>Last-Modified:  Thu Aug 18 05:07:01 UTC 2011
>Originator:     Georg-W. Koltermann
>Release:        FreeBSD 4.6-RELEASE i386
>Organization:
MSC.Software
>Environment:
System: FreeBSD hunter.muc.macsch.com 4.6-RELEASE FreeBSD 4.6-RELEASE #5: Sun Sep 22 22:13:46 CEST 2002 gwk@hunter.muc.macsch.com:/usr/obj/usr/src/sys/HUNTER i386


	
>Description:
JAVA apparently has a problem writing to pipes.  The attached program
writes a bunch of zeros to the pipeline "| cat > somefile".  With the
FreeBSD native JDK 1.3.1 patcheset 6 it randomly hangs at various
loop indices.

The problem also hangs with the SUN Linux JDK 1.3.1 as long as the
JDK runs with -classic.  It also hangs on a Linux system with the
Linux JDK 1.3.1 with -classic.  So it seems there is a bug in the JDK
itself.

However, on any other platform than FreeBSD the JDK runs with a default of
-hotspot, and with that setting the problem does not show up.  On IRIX
it even doesn't show up with the JDK 1.3.1 with green threads and no JIT,
so there must be a way to fix it.

May I ask that we try to fix this problem in the FreeBSD port, since
on FreeBSD the alternative of using -hotspot are not available, or does
not work reliably.

>How-To-Repeat:
----------------test-case-----------snip-------------
import java.io.*;

public class PipeWrite {
    public static void usage() {
	System.err.println("Usage: PipeWrite outfile");
    }
    
    public static void main(String argv[]) throws Exception {
	if (argv.length < 1) {
	    usage();
	    return;
	}
	//	String cmd = "/bin/sh -c 'cat >" + argv[0] + "'";
	String cmd[] = { "/bin/sh", "-c",
			 "cat >" + argv[0] };
	writePipe(cmd);
    }

    private static void writePipe(String pipeCmd[]) throws Exception {
	Process p = Runtime.getRuntime().exec(pipeCmd);

	byte buffer[] = new byte[16384];
	OutputStream pipe = p.getOutputStream();
	InputStream stderr = p.getErrorStream();

	try {
	    for (int i = 0; i < 100; i++) {
		System.out.println("buffer " + i + "...");
		pipe.write(buffer);
		System.out.println("ok");
                //
                // The problem goes away when the following line
                // is uncommented:
		//		Thread.sleep(1);
	    }
	} finally {
	    pipe.close();
	    System.out.println("rc=" + p.waitFor());
	    BufferedReader err =
		new BufferedReader(new InputStreamReader(stderr));
	    String line;
	    while ((line = err.readLine()) != null) {
		System.err.println(line);
	    }
	    err.close();
	}
    }
}
----------------end-test-case-----------snip-------------
>Fix:

	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports->glewis 
Responsible-Changed-By: znerd 
Responsible-Changed-When: Sat Oct 12 10:35:23 PDT 2002 
Responsible-Changed-Why:  
Over to maintainer of java/jdk13, one of the affected 
JDK implementations. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43924 
State-Changed-From-To: open->closed 
State-Changed-By: glewis 
State-Changed-When: Thu Aug 18 05:06:21 UTC 2011 
State-Changed-Why:  
All the jdk13 related ports have been removed. 
I tried the test programme with jdk16 and the problem didn't reproduce. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43924 
>Unformatted:
