tomaswolf commented on issue #409:
URL: https://github.com/apache/mina-sshd/issues/409#issuecomment-1694701918

   Compare also https://stackoverflow.com/questions/14073554 : that is exactly 
the same problem, but _without Apache MINA sshd_ in the loop.
   
   That example just uses `group.shutdownNow()` to close the acceptor and the 
group. Apache MINA sshd in its `Nio2Acceptor` and `Nio2ServiceFactory` first 
explicitly closes the acceptor, and then the group, so that would correspond to
   ```
   acceptor.close();
   group.shutdown();
   ```
   in that example.
   
   What happens is that closing the acceptor causes an 
`AsynchronousCloseException` that should be reported via the 
`CompletionHandler` passed to `acceptor.accept()`.
   
   This appears to work fine on Unix, but on Windows, the task calling 
`CompletionHandler.failed()` ends up being executed via the thread pool of the 
`AsynchronousChannelGroup` after that thread pool has already been shut down.
   
   It's unclear to me whether this a JDK bug. If closing the 
`AsynchronousServerSocketChannel` has such asynchronous effects, then either 
the `AsynchronousChannelGroup` should wait with shutting down its thread pool 
until all such asynchronous effects are done with, or 
`AsynchronousServerSocketChannel.close()` should return a `Future` that could 
be used to wait until the channel is really closed (and a possible 
`AsynchronousCloseException` has been dealt with). Then client code could wait 
on that `Future`, and only then shut down the group.
   
   One way to avoid these exceptions is to give the group a 
`ThreadPoolExecutor` with a rejection policy that simply discards executions on 
an already shut down executor, such as a `CallerRunsPolicy`. But that is more 
like a work-around.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to