Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-1169

BindException on Java >= 11 due to race condition in AbstractPollingIoAcceptor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0.23, 2.1.6, 2.2.1
    • 2.1.7, 2.0.24, 2.2.2
    • None
    • None

    Description

      See also SSHD-1256.

      The main acceptor loop does basically (somewhat simplified):

      while (selectable) {
        registerHandles(); // Process registration queue: add new sockets (from bind()) to the selector with OP_ACCEPT, fulfills their open futures
        int selected = select();
        if (/* nothing to do */) {
          break; // and end the thread; higher layers will create a new one if needed
        }
        if (selected > 0) {
          processHandles(selectedHandles()); // Handle and hand off new connections
        }
        unregisterHandles(); // Process cancel queue: cancel SelectionKey, close ServerSocketChannel, fulfill the cancel future
      }
      

      With Java 11, unbinding a ServerSocketChannel changed:

      Essentially the unbind gives up the socket only at the next select() call. This causes two problems in Apache MINA's acceptor:

      • The unbind future is set "done" before the socket is actually released.
      • If a new binding for one of the unbound sockets is registered before that select() has been done, registerHandles() gets a BindException ("address already in use").

      So for Java >= 11, the code must ensure that there is a select() between processing unbindings and processing new bindings, and the unbind futures must be set "done" only after that select().

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              twolf Thomas Wolf
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h
                  2h