You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/09/25 13:16:00 UTC

[jira] [Work logged] (DIRMINA-1169) BindException on Java >= 11 due to race condition in AbstractPollingIoAcceptor

     [ https://issues.apache.org/jira/browse/DIRMINA-1169?focusedWorklogId=811920&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-811920 ]

ASF GitHub Bot logged work on DIRMINA-1169:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Sep/22 13:15
            Start Date: 25/Sep/22 13:15
    Worklog Time Spent: 10m 
      Work Description: tomaswolf opened a new pull request, #35:
URL: https://github.com/apache/mina/pull/35

   Since Java 11, closing a ServerSocketChannel may release the socket
   only on the next select() call. If we try to register a new binding for
   an unbound socket before the next select, a BindException may be thrown.
   
   Ensure that there is a select() call between unbinding some sockets and
   binding new sockets. Mark the unbind futures as "done" only after that
   intervening select().
   
   Test plan:
   - check out this PR
   - replace NioSocketAcceptor by the 2.0.23 version
   - run the SocketAcceptorTest on a JVM 11 (or newer). It should fail with a BindException.
   - git reset --hard
   - run the SocketAcceptorTest on a JVM 11 (or newer) again. It should pass.
   
   Note that if SocketAcceptorTest is run on a JVM 8, it will succeed in either case.




Issue Time Tracking
-------------------

            Worklog Id:     (was: 811920)
    Remaining Estimate: 0h
            Time Spent: 10m

> BindException on Java >= 11 due to race condition in AbstractPollingIoAcceptor
> ------------------------------------------------------------------------------
>
>                 Key: DIRMINA-1169
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-1169
>             Project: MINA
>          Issue Type: Bug
>    Affects Versions: 2.0.23, 2.1.6, 2.2.1
>            Reporter: Thomas Wolf
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> See also SSHD-1256.
> The main acceptor loop does basically (somewhat simplified):
> {code:java}
> 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
> }
> {code}
> With Java 11, unbinding a {{ServerSocketChannel}} changed:
>  * [JDK-8214430|https://bugs.openjdk.org/browse/JDK-8214430]
>  * [Java 11 Release Notes|https://www.oracle.com/java/technologies/javase/11-relnote-issues.html#JDK-8198562]
> 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()}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org