Skip to content

DIRMINA-1140 - detecting specific case of InterruptedException in NioDatagramAcceptor - #75

Merged
the-thing merged 1 commit into
apache:2.2.Xfrom
the-thing:socket-acceptor-dispose
Oct 3, 2026
Merged

the-thing merged 1 commit into
apache:2.2.Xfrom
the-thing:socket-acceptor-dispose

Conversation

@the-thing

Copy link
Copy Markdown
Member

Fix for DIRMINA-1140

I was able to retrofit JIRA's attached minimal working example into a test case. The title is slightly wrong as this can happen for a single acceptor that is being disposed.

org.apache.mina.core.service.AbstractIoService#dispose(boolean) is the root cause. When a null java.util.concurrent.Executor is passed in org.apache.mina.core.service.AbstractIoService#AbstractIoService creates a new java.util.concurrent.Executors#newCachedThreadPool() and the service is responsible for shutting it down during disposal.

When java.util.concurrent.ExecutorService is shut down it usually interrupts threads which leads to

interrupted exception being thrown here.

Suggested fix is to check the flag if service is being disposed when java.lang.InterruptedException exception is caught and do not rethrow it. I checked and this doesn't happen for org.apache.mina.transport.socket.nio.NioSocketAcceptor etc.

Aleternative fixes:

  • use java.util.concurrent.Semaphore#acquireUninterruptibly() instead of java.util.concurrent.Semaphore#acquire(), but since the thread was interrupted we probably want it to be responsive and do not attempt to acquire the lock (haven't tested this solution).

  • completely ignore - catch without logging / throwing InterruptedException. Not the best since if the custom Executor is passed to NioDatagramAcceptor and is shutdown before the unbind happened, it will lead to similar error, but in this case we actually want to throw it for the user to know about bad shutdown order (demo in org.apache.mina.transport.socket.nio.NioDatagramAcceptorTest#shouldThrowExceptionWhenThreadIsInterruptedAndServiceIsNotDisposing case)

@the-thing
the-thing force-pushed the socket-acceptor-dispose branch from a1c12ed to 0c659be Compare October 2, 2026 07:34
@the-thing
the-thing force-pushed the socket-acceptor-dispose branch from 0c659be to d55fa1b Compare October 2, 2026 07:45
@elecharny

Copy link
Copy Markdown
Contributor

Looks good to me.

And thanks for the cleanup of the code I pushed in a hurry ;-)

@the-thing

Copy link
Copy Markdown
Member Author

Thanks. No probs. When I see a bug or something to improve I see bread on the table ;).

@the-thing
the-thing merged commit 249f203 into apache:2.2.X Oct 3, 2026
9 checks passed
@the-thing
the-thing deleted the socket-acceptor-dispose branch October 3, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants