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

(fc) FileLock.release can deadlock with FileChannel.close

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b57
    • CPU:
      x86
    • OS:
      linux

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.7.0-ea"
        Java(TM) SE Runtime Environment (build 1.7.0-ea-b10)
        Java HotSpot(TM) 64-Bit Server VM (build 1.7.0-ea-b10, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux tidore 2.6.19-gentoo-r5 #1 SMP Thu Feb 15 12:11:59 CET 2007 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ AuthenticAMD GNU/Linux


        A DESCRIPTION OF THE PROBLEM :
        My application happened to call RandomAccessFile.close() and FileLock.release() on a lock created from the FileChannel of the RandomAccessFile in two different threads at the same time. This resulted in a Java level deadlock as shown by the jstack output below.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Sorry, no steps. But it is obvious from the jstack output which locks can be acquired in inconsitent order.


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Found one Java-level deadlock:
        =============================
        "checkpointer":
          waiting to lock monitor 0x00002aaac3b759f0 (object 0x00002aaac2c10958, a java.util.ArrayList),
          which is held by "main"
        "main":
          waiting to lock monitor 0x00002aaac3b75600 (object 0x00002aaac2c109a0, a sun.nio.ch.FileLockImpl),
          which is held by "checkpointer"

        Java stack information for the threads listed above:
        ===================================================
        "checkpointer":
                at sun.nio.ch.FileChannelImpl$SharedFileLockTable.remove(FileChannelImpl.java:1128)
                - waiting to lock <0x00002aaac2c10958> (a java.util.ArrayList)
                at sun.nio.ch.FileChannelImpl.release(FileChannelImpl.java:925)
                at sun.nio.ch.FileLockImpl.release(FileLockImpl.java:38)
                - locked <0x00002aaac2c109a0> (a sun.nio.ch.FileLockImpl)

        "main":
                at sun.nio.ch.FileLockImpl.invalidate(FileLockImpl.java:31)
                - waiting to lock <0x00002aaac2c109a0> (a sun.nio.ch.FileLockImpl)
                at sun.nio.ch.FileChannelImpl$1.release(FileChannelImpl.java:106)
                at sun.nio.ch.FileChannelImpl$SharedFileLockTable.removeAll(FileChannelImpl.java:1155)
                - locked <0x00002aaac2c10958> (a java.util.ArrayList)
                at sun.nio.ch.FileChannelImpl.implCloseChannel(FileChannelImpl.java:104)
                at java.nio.channels.spi.AbstractInterruptibleChannel.close(AbstractInterruptibleChannel.java:97)
                - locked <0x00002aaac2c1f4a8> (a java.lang.Object)
                at java.io.RandomAccessFile.close(RandomAccessFile.java:568)


        REPRODUCIBILITY :
        This bug can be reproduced occasionally.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alanb Alan Bateman
                  Reporter:
                  ndcosta Nelson Dcosta (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: