apache / apache/mina-sshd

SshServer shutdown on Windows may report exceptions about already shut down ExecutorService

Open
#409 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.1k
Forks
400
Avg merge
5d 1h
Merged PRs (30d)
1

Description

### Version

2.10.0

### Bug description

From the [mailing list](https://www.mail-archive.com/users@mina.apache.org/msg07002.html):

Attached code causes circa 50 exceptions:
```
public static void main(String[] args) throws Exception {

for (int i = 0; i < 100; i++) {
SshServer sshd = SshServer.setUpDefaultServer();
SimpleGeneratorHostKeyProvider hostKeyProvider = new SimpleGeneratorHostKeyProvider(
Paths.get(".", "cert"));
hostKeyProvider.setAlgorithm(KeyUtils.RSA_ALGORITHM);

sshd.setKeyPairProvider(hostKeyProvider);
sshd.start();
sshd.stop(false);
}
}
```

### Actual behavior

Lots of exceptions about an already shut down ExecutorService are logged.

This occurs on Windows only; it's not reproducible on Linux.

### Expected behavior

No exceptions are logged; the server shuts down cleanly.

### Relevant log output

```Shell
Exception in thread "Thread-3" Exception in thread "Thread-2"
java.lang.IllegalStateException: Executor has been shut down
at
org.apache.sshd.common.util.ValidateUtils.createFormattedException(ValidateUtils.java:213)
at
org.apache.sshd.common.util.ValidateUtils.throwIllegalStateException(ValidateUtils.java:207)
at
org.apache.sshd.common.util.ValidateUtils.checkState(ValidateUtils.java:184)
at
org.apache.sshd.common.util.threads.NoCloseExecutor.execute(NoCloseExecutor.java:100)
at
java.base/sun.nio.ch.AsynchronousChannelGroupImpl.executeOnPooledThread(AsynchronousChannelGroupImpl.java:190)
at java.base/sun.nio.ch.Invoker.invokeIndirectly(Invoker.java:215)
at java.base/sun.nio.ch.Invoker.invokeIndirectly(Invoker.java:316)
at
java.base/sun.nio.ch.WindowsAsynchronousServerSocketChannelImpl$AcceptTask.failed(WindowsAsynchronousServerSocketChannelImpl.java:288)
at java.base/sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:389)
at java.base/java.lang.Thread.run(Thread.java:1589)
```

### Other information

OS: Windows

Originally reported using temurin 19.0.2.7 and Apache MINA sshd 2.10.0, but it also occurs with other JVMs/JDKs.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the shutdown loop on Windows with the example in the issue, then inspect NoCloseExecutor.java and the JDK asynchronous server-channel shutdown path shown in the stack trace. Trace the shutdown ordering and verify that repeated SshServer start/stop cycles complete without logging ExecutorService exceptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.