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

Race: Thread::interrupt vs. AbstractInterruptibleChannel.begin

XMLWordPrintable

    • b11
    • Verified

        There is a race interrupting a thread B that begins a blocking NIO operation, e.g. socket accept.

        Thread A.........................Thread B

                                         enters ServerSocketChannelImpl::accept
                                           enters AbstractInterruptibleChannel::begin
        enters B.interrupt
            reads B.nioBlocker -> null
                                                writes B.nioBlocker = AbstractInterruptibleChannel.interruptor
                                                reads B.interrupted -> false
            writes B.interrupted = true
                                           leaves AbstractInterruptibleChannel::begin
                                           [...]
                                               enters Net.accept

        Result: B successfully calls accept and remains there even though it was interrupted.

        How to reproduce:

        - apply decide_race_in_thread_interrupt.patch (attached)

        - run ThreadInterruptRace.java (also attached) like this
          java ThreadInterruptRace.java dosleep

        The issue was found analyzing failures of jck test api/java_net/ServerSocket/AcceptInterruptibleTests_PlatformThreads

        Potential fix: write `interrupted` field before reading `nioBlocker` in Thread::interrupt

          1. decide_race_in_thread_interrupt.patch
            2 kB
            Richard Reingruber
          2. LotsOfInterrupts.java
            3 kB
            Alan Bateman
          3. Thread.patch
            1 kB
            Alan Bateman
          4. ThreadInterruptRace.java
            3 kB
            Richard Reingruber

              rrich Richard Reingruber
              rrich Richard Reingruber
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Created:
                Updated:
                Resolved: