Open yonatankarimish opened 4 years ago
While testing the Socket.connect() method (without invoking it from your library) the JVM managed to maintain 65k+ open sockets: (the maximum open files I allocated the JVM)
// Static members
private static final SocketFactory socketFactory = SocketFactory.getDefault();
//This section runs concurrently
try {
Socket socket = socketFactory.createSocket();
InetSocketAddress address = new InetSocketAddress(sessionEngine.localhostConfig.getHost(), sessionEngine.localhostConfig.getPort());
socket.connect(address, connectTimeout);
Thread.sleep(preCloseWait);
socket.close();
} catch (Exception e) {
//whatever...
}
What is causing the core dump? Keep in mind that the lib does a lot more than "just opening a socket".
I didn't have core dumps enabled. But according to the logs I originally attached, invoking sshClient.connect(), which ultimately invoked socket.connect(), causing a segmentation fault in the JVM memory which resulted in a crash.
The culprit class is SocketClient, in which You first declare a socket factory [line 38]:
private SocketFactory socketFactory = SocketFactory.getDefault();
and the source code throwing the exception is the connect() method [line 126]:
public void connect(String hostname, int port) throws IOException {
if (hostname == null) {
connect(InetAddress.getByName(null), port);
} else {
this.hostname = hostname;
socket = socketFactory.createSocket();
socket.connect(new InetSocketAddress(hostname, port), connectTimeout);
onConnect();
}
}
Since I don't pass a null hostname, and since your connectionTimeout = 0 (don't timeout the connection), this can be rewritten as:
public void connect(String hostname, int port) throws IOException {
socket = socketFactory.createSocket();
socket.connect(new InetSocketAddress(hostname, port), 0);
onConnect();
}
making the only difference between my socket opening test and your method the onConnect() callback after the socket.connect() call.
I don't know what could be the cause of the segmentation fault. the onConnect() callback from a previous invocation? the sshClient? Thread-safety issues? To be honest, communication protocols are not my area of expertise, so I can only guess what could be causing the problem.
@hierynomus Checking again after 4 months... Any chance you can help me out with this issue?
Core dumps, or segv's of this kind are not in the library, also see the dump you posted. It's deep in C/native code. I cannot help here.
Hi
When working according to your comments on issue #611 , I was opening a large number of ssh clients using the following code:
I ran this code in a multi-threaded environment, resulting in a large number of clients open at the same time. Around ~2500+ clients my JVM crashed unexpectedly with no crash logs. When checking my system logs, they pointed to a crash report from the Java process itself. The logs are quite long, so i'm attaching the relevant part here below.
Any idea what i'm doing wrong / what could be causing this?