"java.net.SocketException: Connection reset" when running a simpleSSL client

10,977

Solution 1

java.net.SocketException: Connection reset is generally speaking caused by remote peer closed connection.

I guess your SSL config didn't fit well with server. Suggestion here is to debug SSL connection to find root cause.

Try to append this system property to your JVM params:

-Djavax.net.debug=all

More details here

Solution 2

I was able to fix this in Java 1.7 by specifying: SSLContext sc = SSLContext.getInstance("TLSv1.2");

Share:
10,977
user6217189
Author by

user6217189

Updated on November 23, 2022

Comments

  • user6217189
    user6217189 over 1 year

    I am attempting to create a client/server using the SSL communication. I followed the instructions listed here (https://www.rabbitmq.com/ssl.html).

    I am greeted with this error:

    while running the server :

    java.net.SocketException: Connection reset
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at java.io.DataOutputStream.flush(DataOutputStream.java:123)
        at com.rabbitmq.client.impl.SocketFrameHandler.sendHeader(SocketFrameHandler.java:129)
        at com.rabbitmq.client.impl.SocketFrameHandler.sendHeader(SocketFrameHandler.java:134)
        at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:277)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:678)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:722)
    

    while using the client :

    Exception in thread "main" java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at sun.security.ssl.InputRecord.readFully(Unknown Source)
        at sun.security.ssl.InputRecord.read(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.waitForClose(Unknown Source)
        at sun.security.ssl.HandshakeOutStream.flush(Unknown Source)
        at sun.security.ssl.Handshaker.kickstart(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.kickstartHandshake(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source)
        at sun.security.ssl.AppOutputStream.write(Unknown Source)
        at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
        at java.io.BufferedOutputStream.flush(Unknown Source)
        at java.io.DataOutputStream.flush(Unknown Source)
        at com.rabbitmq.client.impl.SocketFrameHandler.sendHeader(SocketFrameHandler.java:129)
        at com.rabbitmq.client.impl.SocketFrameHandler.sendHeader(SocketFrameHandler.java:134)
        at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:277)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:678)
        at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:722)
        at rmqClient.simpleSSL.main(simpleSSL.java:23)
    

    here's my rabbit.config file :

    [
        {ssl, [{versions, ['tlsv1.2', 'tlsv1.1']}]},
        {
        rabbit,
        [
              {ssl_listeners, [5675]},
          {ssl_options, [{cacertfile,"sslConn/ca_certificate.pem"},
                              {certfile,  "sslConn/server_certificate.pem"},
                              {keyfile,   "sslConn/server_key.pem"},
                              {versions, ['tlsv1.2', 'tlsv1.1']},
                              {ciphers,  [{ecdhe_ecdsa,aes_128_cbc,sha256},
                                          {ecdhe_ecdsa,aes_256_cbc,sha}]}
                             ]},     
              {tcp_listeners, [5672]},
              {loopback_users, []}
            ]
        }
    ].
    

    here's also my client code :

        factory.setHost("10.3.9.139");
        factory.setPort(5673);
        factory.setUsername("User1");
        factory.setPassword("User1");
        factory.useSslProtocol();
        Connection conn = factory.newConnection();
        Channel channel = conn.createChannel();
        channel.queueDeclare("rabbitmq-java-test", false, true, true, null);
        channel.basicPublish("", "rabbitmq-java-test", null, "Hello, World".getBytes());
    
  • ChanGan
    ChanGan about 7 years
    I am getting same error when trying to hit from soapui.. Can you please let me know that where do i need to add -Djavax.net.debug=all?
  • ChanGan
    ChanGan about 7 years
    I have added in SoapUI-5.0.0.vmoptions.. Let me see i am able to resolve the issue. I did not get any clue.. getting same errorlog..
  • Sridhar Sarnobat
    Sridhar Sarnobat almost 6 years
    I wish I'd known about -Djavax.net.debug=all about 5 weeks ago! If you're using Tomcat, you'll need to find the right place in catalina.sh to add it.