Repository navigation
100% cpu when using SSL #458
Copy link
Copy link
Closed
Description
Connecting to ws:// I see 3% cpu usage. But when using SSL and connecting to wss:// I see 100% cpu usage. I can't reproduce locally so it's hard to know what's going on. I'm also using getSslContext() for a web server so I know it's correct.
try {
aSocketServer = new ASocketServer(443);
} catch (UnknownHostException e) {
e.printStackTrace();
}
try {
SSLContext sslContext = getSslContext();
if (sslContext != null) {
aSocketServer.setWebSocketFactory(new DefaultSSLWebSocketServerFactory(sslContext));
}
} catch (Exception e) {
e.printStackTrace();
}
public static SSLContext getSslContext() {
try {
final char[] pass = "pass".toCharArray();
final KeyStore keyStore = KeyStore.getInstance("JKS");
try (final InputStream is = new FileInputStream("file.jks")) {
keyStore.load(is, pass);
}
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, pass);
final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
final SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new java.security.SecureRandom());
return sc;
} catch (KeyStoreException | KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | CertificateException | IOException exc) {
throw new RuntimeException(exc);
}
}
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import org.java_websocket.WebSocket;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
import java.util.Date;
public class AsSocketServer extends WebSocketServer {
public ASocketServer( int port ) throws UnknownHostException {
super( new InetSocketAddress( port ) );
}
public ASocketServer( InetSocketAddress address ) {
super( address );
}
@Override
public void onOpen( WebSocket conn, ClientHandshake handshake ) {
}
}
Reactions are currently unavailable
Activity
becast commentedon Apr 23, 2017
I submitted a PR that might solve your issue 203470b
marci4 commentedon Apr 23, 2017
Hello @dan335,
could you please tell me which version of the lib you are using right now?
It should be 1.3.2.
As it looks like you are using the lib on a normal client and not android, is this right?
Do you know with which clients this problem occurs?
Greetings
marci4
dan335 commentedon Apr 24, 2017
The version is 1.3.2. Normal client not android. I was using chrome with plain javascript websockets.
I got rid of SSL so unfortunately I can't test your fix.
marci4 commentedon Apr 24, 2017
Hello @dan335
was able to reproduce this issue with https://www.htbridge.com/ssl test suite.
The fix provided by @becast is working.
Going to release it with the new version 1.3.3.
Greetings
marci4
Fixing 100% CPU untilisation when SSL negotiations fail