简体   繁体   中英

Application throwing java.net.SocketTimeoutException: Read timed out while reading from TCP socket

I have an application which makes a sync call to IBMSafer system through TCP/IP channel.

The data received starts and end with <IRIS> tag respectively, which has been configured within the application to poll data only until the point until we receive an end tag of </IRIS> .

However, the application is throwing the following exception:

java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method) ~[?:1.8.0_282]
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[?:1.8.0_282]
    at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[?:1.8.0_282]
    at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_282]
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) ~[?:1.8.0_282]
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) ~[?:1.8.0_282]
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) ~[?:1.8.0_282]
    at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[?:1.8.0_282]
    at java.io.BufferedReader.fill(BufferedReader.java:161) ~[?:1.8.0_282]
    at java.io.BufferedReader.read1(BufferedReader.java:212) ~[?:1.8.0_282]
    at java.io.BufferedReader.read(BufferedReader.java:286) ~[?:1.8.0_282]
    at java.io.Reader.read(Reader.java:140) ~[?:1.8.0_282]

The error isn't related to a response delay from the server, as I can connect to the server and get a response back from my putty session using this command within milliseconds:

nc --ssl <Server_IP>

Seems like the application is failing to read from the request queue/or looking for more buffer which indefinitely gets stuck, and as soon as timeout is reached, throws the error.

From the application point of view, configuration is done something as below:

READ FROM -- `SERVER IP`
PORT --  `PORT NUMBER`
READ FROM SOCKET STARTS FROM --- `""` (empty string)
READ FROM SOCKET TILL --- `</IRIS>` is encountered.
OPEN SOCKET PER MSG --- `NO`
TIMEOUT --- `5 sec`

Already banged my head against this for hours.

Edit : The application is supposed to send something like:

<IRIS> .... request payload .... </IRIS>

and read something like:

<IRIS> .... response payload .... </IRIS>

App needs to stop reading response buffer from the socket as soon as </IRIS> is encountered. This was done due to a line factoring issue.

My Application is sending correct info, as request payload is also captured in logs, which if sent exactly as it is via netcat command to the IBMSafer server, brings back the string response.

The issue has been fixed. The problem was occuring because i was using a plain Socket connection from my client application, but IBMSafer actually has a SSLServerSocket which only establishes a connection if the client also is using an SSL security channel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM