Socket error code 0

socket error code 0

This error cannot be easily reproduced with a single curl command. {"code":4,"message":"Forbidden"}. The request was denied in the allowRequest. 10061 corresponds to the code of the connection refused socket error code in Windows (also known as WSAECONNREFUSED). Title: ATP6100/SWAN: Connect lost: Socket error code 4120 LINE 1 on CPU 0 via TCPIP $ZB01A using TCP/IP via QIO designated PATH B, Connect lost Socket.

Thematic video

[FIXED] Error Code ERR_SOCKET_NOT_CONNECTED Problem Issue

Socket error code 0 - that necessary

java.net.SocketException: Unrecognized Windows Sockets error: 0: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) at java.net.SocketInputStream.read(SocketInputStream.java:171) at java.net.SocketInputStream.read(SocketInputStream.java:141) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read(BufferedInputStream.java:265) at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:598) at java.lang.Thread.run(Thread.java:748) 

DIRECT CAUSE

JDK bug reported on AdoptOpenJDK: https://github.com/AdoptOpenJDK/openjdk-build/issues/1441 
JDK bug reported on OpenJDK: https://bugs.openjdk.java.net/browse/JDK-8210147

The bug is that the Windows socket API WSAGetLastError() is invoked twice before throwing SocketException.

The first invocation captures the original socket error during recv() invocation, late on during the population of SocketException, WSAGetLastError() is invoked again and the 2nd invocation always returns error code 0 as the previous invocation also resets the last socket error code to 0 therefore the original socket error code has been lost during 2nd invocation.

ROOT CAUSE

One of the root cause is that long JVM GC procedure pauses the thread of java.net.SocketInputStream and causes Windows socket recv() timeout.

SOLUTION1

Please adopt OpenJDK8u272 (or late version) and tune Mule runtime JVM heap settings, the maximum Java heap size needs to be increased if heap size is insufficient.

SOLUTION2

If you have to use a JDK8 distribution older than OpenJDK8u272, please review and tune Mule runtime JVM heap settings, the maximum Java heap size needs to be increased if heap size is insufficient.
Please also adopt AMQP Connector 1.5.0 or later version which allow explicitly disabling socket timeout on underlay windows socket. This involves the following changes on both RabbitMQ server and Mule Application side:

  1. On RabbitMQ server, enable the following settings tcp_listen_options.keepalive = true heartbeat = 6000 #Note: 6000 can be changed to other number
  2. Set heartbeatTimeout="0" on amqp:connection configuration in the Mule Application <amqp:connection ... heartbeatTimeout="0">
  3. Add the following <amqp:socket-configuration> to <amqp:connection>, and soTimeout has to be 0 with keepAlive enabled <amqp:socket-configuration keepAlive="true" soTimeout="0"/>
    For example: <amqp:config name="amqpConfig2" doc:name="AMQP Config" doc:id="0ddc4cfa-cf05-457a-83a0-9b884c7d3d37"> <amqp:connection host="${amqp.host1}" port="${amqp.port}" virtualHost="${amqp.virtualHost}" username="${amqp.username}" password="${amqp.password}" useTls="true" heartbeatTimeout="0"> <reconnection> <reconnect-forever frequency="5000" /> </reconnection> <tls:context> <tls:trust-store path="${amqp.trustedStorePath}" password="${amqp.trustedStorePassword}" type="jks" /> <tls:key-store type="pkcs12" path="${amqp.keyStorePath}" keyPassword="${amqp.keyStorePassword}" password="${amqp.keyStorePassword}" /> </tls:context> <amqp:socket-configuration keepAlive="true" soTimeout="0"/> <amqp:fallback-addresses> <amqp:fallback-address host="${amqp.host2}" port="${amqp.port}" /> <amqp:fallback-address host="${amqp.host3}" port="${amqp.port}" /> <amqp:fallback-address host="${amqp.host4}" port="${amqp.port}" /> </amqp:fallback-addresses> </amqp:connection> <amqp:consumer-config ackMode="AUTO" numberOfConsumers="${amqp.numberOfConsumers}" /> <amqp:quality-of-service-config prefetchCount="${amqp.prefetchCount}" /> </amqp:config>