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

Race: Thread::interrupt vs. AbstractInterruptibleChannel.begin

    XMLWordPrintable

Details

    • b11
    • Verified

    Backports

      Description

        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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: