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

Ready java.nio.channels.Pipe.source() doesn't wakeup selector

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • core-libs
    • x86
    • windows_nt



      Name: rmT116609 Date: 05/14/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      FULL OPERATING SYSTEM VERSION :

      Windows NT Version 4.0, Windows 2000

      DESCRIPTION OF THE PROBLEM :
      If I write to the sink end of a pipe while a selector is selecting on the source end, it doesn't cause the call to select to return even though my write seems to have completed successfully.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the example code on NT (it works ok on Solaris 8 with single and multi processor), you'll see it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected (line order may vary slightly)

      Starting selector thread.
      waiting for selector thread to start
      registering source end
      notified thread started
      before select
      thread started. sleep for a second to make sure selector
      thread gets to select.
      writing to sink side of pipe
      wrote 1 bytes
      waiting for select to return
      after select
      notified second time
      select return notification recieved
      end of main thread
      end of selector thread

      --------------------------------------------
      Actual:

      Starting selector thread.
      waiting for selector thread to start
      registering source end
      notified thread started
      thread started. sleep for a second to make sure selector
      thread gets to select.
      before select
      writing to sink side of pipe
      wrote 1 bytes
      waiting for select to return

      (blocks here forever)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no error message, vm blocks indefinitely

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.nio.*;
      import java.nio.channels.*;

      public class TestPipe
      {
        public static void main(String[] args_)
        {
          try
          {
            final Pipe _wakeupPipe = Pipe.open();
            _wakeupPipe.sink().configureBlocking(false);
            _wakeupPipe.source().configureBlocking(false);

            ByteBuffer _readBuffer = ByteBuffer.allocate(1);
            ByteBuffer _writeBuffer = ByteBuffer.allocate(1);
            _writeBuffer.put((byte)0);
            _writeBuffer.flip();
            _writeBuffer.mark();
            
            final Selector _selector = Selector.open();

            Thread t = new Thread() {
                public void run()
                {
                  try
                  {
                    System.err.println("registering source end");
                    _wakeupPipe.source().register(_selector, SelectionKey.OP_READ);
                    synchronized (TestPipe.class)
                    {
                      TestPipe.class.notify();
                      System.err.println("notified thread started");
                    }
                    System.err.println("before select");
                    _selector.select(0);
                    System.err.println("after select");
                    synchronized (TestPipe.class)
                    {
                      TestPipe.class.notify();
                      System.err.println("notified second time");
                    }
                    System.err.println("end of selector thread");
                  }
                  catch (Exception x)
                  {
                    x.printStackTrace();
                  }
                }
              };

            System.err.println("Starting selector thread.");
            t.start();

            synchronized (TestPipe.class)
            {
              System.err.println("waiting for selector thread to start");
              TestPipe.class.wait();
            }
            System.err.println("thread started. sleep for a second to make sure
      selector thread gets to select.");
            
            Thread.sleep(1000); // just to make sure it gets into select

            System.err.println("writing to sink side of pipe");
            int i = _wakeupPipe.sink().write(_writeBuffer);
            System.err.println("wrote "+i+" bytes");
            synchronized (TestPipe.class)
            {
              System.err.println("waiting for select to return");
              TestPipe.class.wait();
              System.err.println("select return notification recieved");
            }
            System.err.println("end of main thread");
          }
          catch (Exception x)
          {
            x.printStackTrace();
          }
        }
      }

      ---------- END SOURCE ----------
      (Review ID: 146529)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: