Skip to content

100% cpu when using SSL #458

Closed
Closed

Description

@dan335

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 ) {
    }
}

Activity

  1. becast commented on Apr 23, 2017

    @becast
    Contributor

    I submitted a PR that might solve your issue 203470b

  2. marci4 commented on Apr 23, 2017

    @marci4
    Collaborator

    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

  3. dan335 commented on Apr 24, 2017

    @dan335
    Author

    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.

  4. marci4 commented on Apr 24, 2017

    @marci4
    Collaborator

    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

  5. self-assigned this
    on Apr 24, 2017
  6. added this to the Release 1.3.3 milestone on Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions