Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4499763

Pipelined I/O: java.io.IOException: Write end dead [1.4.2]

XMLWordPrintable

    • b24
    • generic
    • generic



        Name: elR10090 Date: 09/05/2001



        JDK 1.4.0beta3-b78 fails against a simple test trying to pass
        one text line through PipedInputStream/PipedOutputStream line.

        The test a connected pair of PipedInputStream & PipedOutputStream,
        and starts two threads -- one reading & another writing a string
        via the pipeline. But, the reading thread suffers IOException
        while expecting to observe EOF on the PipedInputStream:

            >>>> javac PrintStreamTest.java
            >>>> java PrintStreamTest
            test message
            java.io.IOException: Write end dead
             at java.io.PipedInputStream.read(PipedInputStream.java:216)
             at java.io.PipedInputStream.read(PipedInputStream.java:277)
             at java.io.InputStream.read(InputStream.java:91)
             at java.io.InputStreamReader$ConverterFiller.fill(InputStreamReader.java:248)
             at java.io.InputStreamReader.read(InputStreamReader.java:511)
             at java.io.BufferedReader.fill(BufferedReader.java:139)
             at java.io.BufferedReader.readLine(BufferedReader.java:302)
             at java.io.BufferedReader.readLine(BufferedReader.java:365)
             at PrintStreamTest$Redirector.run(PrintStreamTest.java:50)

            >>>> java -version
            java version "1.4.0-beta3"
            Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b78)
            Java HotSpot(TM) Client VM (build 1.4.0-beta3-b78, mixed mode)

        Following is the source code for the "PrintStreamTest.java":

        import java.io.*;

        public class PrintStreamTest {
            final static int RACE_CONDITION = 10; // seconds

            public static void main(String args[])
                throws IOException, InterruptedException
            {
                PipedInputStream in = new PipedInputStream();
                PipedOutputStream out = new PipedOutputStream(in);

                Redirector redirector = new Redirector(in,System.out);
                redirector.start();

                PrintStream testOut = new PrintStream(out);
                TestThread testThread = new TestThread(testOut);
                testThread.start();
                testThread.join();
                testOut.close();

                redirector.join();
            }

            private static class TestThread extends Thread {
                private PrintStream out;
                public TestThread(PrintStream out) {
                    this.out = out;
                }
                public void run() {
                    try {
                        sleep(RACE_CONDITION * 1000L);
                    } catch (InterruptedException exception) {
                        exception.printStackTrace(out);
                        return;
                    };
                    out.println("test message");
                }
            }

            private static class Redirector extends Thread {
                private BufferedReader in;
                private PrintStream out;
                public Redirector(InputStream in, PrintStream out) {
                    this.in = new BufferedReader(new InputStreamReader(in));
                    this.out = out;
                }
                public void run() {
                    for (String line; ; )
                        try {
                            line = in.readLine();
                            if (line == null)
                                break;
                            out.println(line);
                        } catch (IOException exception) {
                            exception.printStackTrace(out);
                            return;
                        }
                }
            }
        }

        Probably, this testcase reproduces the known intermittent failure
        filed against HS 1.0 and closed as "will not fix":

            4211703 PipedInputStream fails to read the correct number of bytes

        Please note, that the exception doesn't happen if RACE_CONDITION
        value is reassigned to less than 2 seconds.

        This bug affects the following testbase_nsk test stressing-out logging
        into ConsoleHandler (the test will appear with the next "r07" release
        of the testbase):

            nsk/logging/stress/threads/cnshsl001

        While the simplified testcase "PrintStreamTest.java" demonstrates the
        problem only on Solaris/SPARC; the Logging API stress test "cnshsl001"
        fails on all platforms -- that is why I marked this bug's O/S and
        hardware versions as "generic".

        The following simplified testcase "ConsoleHandlerThreadsTest.java"
        also demonstrates the exception on all platforms (intermittently
        on Windows):

            import java.io.*;
            import java.util.logging.*;

            /**
             * Check if ConsoleHandler can successfully log when <tt>stderr</tt>
             * is reassigned with <tt>setErr()</tt> method of the <tt>System</tt>.
             */
            public class ConsoleHandlerThreadsTest {
                final static int THREADS_NUMBER = 10;

                public static void main(String args[])
                    throws IOException, InterruptedException
                {
                    PipedInputStream in = new PipedInputStream();
                    PipedOutputStream out = new PipedOutputStream(in);

                    Redirector redirector = new Redirector(in,System.out);
                    redirector.start();

                    PrintStream fakeErr = new PrintStream(out);
                    PrintStream stdErr = System.err;
                    System.setErr(fakeErr);

                    Handler handler = new ConsoleHandler();
                    handler.setLevel(Level.ALL);
                    handler.setFormatter(new TrivialFormatter());

                    Logger logger = Logger.getLogger("test.logger000");
                    logger.setLevel(Level.ALL);
                    logger.addHandler(handler);

                    Thread threads[] = new TestThread [ THREADS_NUMBER ];
                    for (int i=0; i<threads.length; i++)
                        threads[i] = new TestThread(i+1, logger);
                    for (int i=0; i<threads.length; i++)
                        threads[i].start();
                    for (int i=0; i<threads.length; i++)
                        threads[i].join();

                    logger.removeHandler(handler);
                    handler.close();

                    System.setErr(stdErr);
                    fakeErr.close();

                    redirector.join();
                }
            
                private static class TestThread extends Thread {
                    private Logger logger;
                    private int id;
                
                    public TestThread(int id, Logger logger) {
                        this.logger = logger;
                        this.id = id;
                    }
                
                    public void run() {
                        logger.finest("message #" + id);
                    }
                }
            
                private static class Redirector extends Thread {
                    private BufferedReader in;
                    private PrintStream out;
                
                    public Redirector(InputStream in, PrintStream out) {
                        this.in = new BufferedReader(new InputStreamReader(in));
                        this.out = out;
                    }
                
                    public void run() {
                        for (String line; ; )
                            try {
                                line = in.readLine();
                                if (line == null)
                                    break;
                                out.println(line);
                            } catch (IOException exception) {
                                exception.printStackTrace(out);
                                return;
                            }
                    }
                }
            
                final static String LINE_SEPARATOR = System.getProperty("line.separator");

                private static class TrivialFormatter extends Formatter {
                    public String format(LogRecord record) {
                        return record.getMessage() + LINE_SEPARATOR;
                    }
                }
            }

        ======================================================================

        Name: elR10090 Date: 09/11/2001



        Alexey Gibadullin, ###@###.###

        This bug also affects the following tests:

            nsk/logging/stress/threads/cnshml001
            nsk/logging/stress/threads/cnshml002


        ======================================================================

        Name: elR10090 Date: 09/12/2001



        Following is the full list of testbase_nsk tests
        failing due to this bug:

            nsk/logging/stress/threads/cnshsl001
            nsk/logging/stress/threads/cnshml001
            nsk/logging/stress/threads/cnshml002
            nsk/logging/stress/threads/cnmhml001
            nsk/logging/stress/threads/cnmhml002
            nsk/logging/stress/threads/smmhml001
            nsk/logging/stress/threads/smmhml002

        I add this notice to let the automated script preparing
        Tonga FAIL_LIST for testbase_nsk executions to include
        these test names into the list of expected failures.

        ======================================================================

        Name: elR10090 Date: 11/19/2001



        Alexey Gibadullin, ###@###.###

        One more test is affected by this bug:

            nsk/logging/stress/threads/smshml002
            
        The failure was observed on Linux and Solsparc platforms in
        various modes, but not in all runs (approximatly 1 out of 5 cases).



        ======================================================================

        Name: elR10090 Date: 03/09/2004


        The failure still looks reproducible against Tiger-b41;
        I've observed multiple test fails for various platforms
        (Windows, Linux, Solaris/x86, Solaris/SPARC/v8/v9) and
        for various VM modes (-server and -client, mode default,
        -Xcomp, java_g).

        Though, the following two tests fail only for java_g:

            nsk/logging/stress/threads/smshml001
            nsk/logging/stress/threads/smshsl001

        I'm adding the test names here to put them to the list
        of expected test failures (ie: vm.knownbugs.v15).

        ======================================================================

              mmcclosksunw Michael Mccloskey (Inactive)
              latkinsunw Latkin Latkin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: