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

(ch) AsynchronousFileChannel hangs with internal error when reading locked file

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b08
    • CPU:
      x86_64
    • OS:
      windows_7

      Backports

        Description

        FULL PRODUCT VERSION :
        Reproduced on

        java version "1.8.0_131"
        Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
        Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

        java version "1.8.0_102"
        Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
        Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)


        CANNOT reproduce on

        java version "1.7.0_45"
        Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
        Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Reproduced on other Windows 7 PCs

        A DESCRIPTION OF THE PROBLEM :
        If get lock on AsynchronousFileChannel, read, write, close it and repeat these steps then read operation will likely hung with internal IllegalArgumentException. The problem is that the ReadTask tries to update the byte buffer position with unacceptable value, crushes and never call CompletionHandler.

        See the example.

        REGRESSION. Last worked in version 7u76

        ADDITIONAL REGRESSION INFORMATION:
        java version "1.7.0_45"
        Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
        Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the given example, see result and stderr

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Completed without errors
        ACTUAL -
        Hungs with an exception in stderr

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "Thread-4" java.lang.IllegalArgumentException
        at java.nio.Buffer.position(Buffer.java:244)
        at sun.nio.ch.WindowsAsynchronousFileChannelImpl$ReadTask.updatePosition(WindowsAsynchronousFileChannelImpl.java:417)
        at sun.nio.ch.WindowsAsynchronousFileChannelImpl$ReadTask.completed(WindowsAsynchronousFileChannelImpl.java:483)
        at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:397)
        at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)

        REPRODUCIBILITY :
        This bug can be reproduced often.

        ---------- BEGIN SOURCE ----------
        import java.nio.ByteBuffer;
        import java.nio.channels.AsynchronousFileChannel;
        import java.nio.channels.FileLock;
        import java.nio.file.Paths;

        import static java.nio.file.StandardOpenOption.*;


        public class Main {

            public static void main(String[] args) throws Exception {
                for (int i=0; i < 1000; i++) {
                    AsynchronousFileChannel f = AsynchronousFileChannel.open(Paths.get("r:/tmp"), READ, WRITE, CREATE);
                    FileLock l = f.lock().get();
                    f.read(ByteBuffer.allocate(16), 0).get();
                    f.write(ByteBuffer.allocate(16), 0).get();
                    l.release();
                    f.close();
                }
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Close the channel and retry to lock/read operations. After several attempts it works.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                bpb Brian Burkhalter
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: