mina-sshd
mina-sshd copied to clipboard
Connect to server failed when get session:error: 在一个非套接字上尝试了一个操作
Version
2.9.2
Bug description
Recently, we switched from jsch to mina ssh. In some of our customers' environments, we encountered the following error when connecting to the customer's machine through SSH. When we roll back to the version using jsch, we can connect the environment properly.
Operating system: windows server 2016 target environment ip: IPv6
Actual behavior
connection build failed.
Expected behavior
Connect the device properly.
Relevant log output

Caused by: java.io.IOException: 在一个非套接字上尝试了一个操作。
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.connect0(Native Method) ~[?:1.8.0_332]
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.access$200(WindowsAsynchronousSocketChannelImpl.java:43) ~[?:1.8.0_332]
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ConnectTask.run(WindowsAsynchronousSocketChannelImpl.java:235) ~[?:1.8.0_332]
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl.implConnect(WindowsAsynchronousSocketChannelImpl.java:382) ~[?:1.8.0_332]
at sun.nio.ch.AsynchronousSocketChannelImpl.connect(AsynchronousSocketChannelImpl.java:210) ~[?:1.8.0_332]
at org.apache.sshd.common.io.nio2.Nio2Connector.connect(Nio2Connector.java:72) ~[sshd-core-2.9.2.jar:2.9.2]
at org.apache.sshd.client.SshClient.doConnect(SshClient.java:632) ~[sshd-core-2.9.2.jar:2.9.2]
at org.apache.sshd.client.SshClient.doConnect(SshClient.java:615) ~[sshd-core-2.9.2.jar:2.9.2]
at org.apache.sshd.client.SshClient.connect(SshClient.java:546) ~[sshd-core-2.9.2.jar:2.9.2]
at org.apache.sshd.client.SshClient.connect(SshClient.java:538) ~[sshd-core-2.9.2.jar:2.9.2]
at org.apache.sshd.client.session.ClientSessionCreator.connect(ClientSessionCreator.java:74) ~[sshd-core-2.9.2.jar:2.9.2]
at org.apache.sshd.client.session.ClientSessionCreator.connect(ClientSessionCreator.java:57) ~[sshd-core-2.9.2.jar:2.9.2]
Other information
our code :
The error message appears to indicate that this is Windows error 10038 ("An operation was attempted on something that is not a socket."). Searching the Internet for "OS 10038" or related things (like the Chinese error message text!) gets quite a few hits. Some include the Apache HTTP server; compare the mod_winnt configuration of Apache httpd 2.2. (In newer releases, that config was removed; compare the httpd 2.4 documentation: it appears the problem is still there, but httpd falls back to another API if there are too many failures.)
The cause appears to be unclear. Most hits report this occurring suddenly from time to time in otherwise working applications. It's being mentioned for many different applications. Some mention it was some corruption in the Windows TCP/IP stack, and some people claim running "netsh winsock reset" would resolve this problem.
It is possible that the AsynchronousSocketChannel used by the Apache MINA sshd NIO2 transport back-end exercises some Windows code that triggers a bug in Windows. The Java native code does use the Windows ConnectEx function... maybe that can have the same problem as AcceptEx mentioned on other sites. JSch definitely doesn't use AsynchronousSocketChannel.
You could try using the sshd-mina or sshd-netty transport back-ends with Apache MINA sshd; those also do not use AsynchronousSocketChannel.
You could also try using a later Java version. Try Java 11 or 17, or maybe even 19.
We can't go to the customer site to check, so we'll contact the customer to try "netsh winsock reset"。