edit-icon download-icon

Java SDK error: SocketTimeoutException

Last Updated: Apr 11, 2018

Symptom

The SDK throws SocketTimeoutException during application requests.

Cause

If the difference between the Receive time (the time when the SDK receives data) and the Send time (the time when the SDK sends data) is greater than the value of SocketTimeout, the SDK throws SocketTimeoutException. In this period, the application sends a request (including network transmission), the server processes the request, and the application receives a response (including network transmission). You can set the value of SocketTimeout when creating the OTSClient. The default value of SocketTimeout is 15s.

Resolution

Depending on the issue, SocketTimeoutException may be resolved as follows:

  • The network is disconnected.

    Run the ping or curl command to check the network connection, especially if SocketTimeoutException is thrown for all requests.

    1. ping aaaa.cn-hangzhou.ots.aliyuncs.com
    2. curl aaaa.cn-hangzhou.ots.aliyuncs.com
    • If the network is connected and the curl command is run, a result similar to the following is returned:

      1. <?xml version="1.0" encoding="UTF-8"?>
      2. <Error><Code>OTSUnsupportOperation</Code><Message>Unsupported operation: ''.</Message><RequestID>00054ec5-822c-8964-adaf-990a07a4d0c9</RequestID><HostID>MTAuMTUzLjE3NS4xNzM=</HostID></Error>
    • If the network is disconnected, check whether an intranet endpoint is being used in a non-ECS environment.

  • The server processing time exceeds the time the SDK specified for SocketTimeout.

    The Table Store server generally processes a request within 15s. If the processing time exceeds the time-out period on the server (typically 10s), the server returns OTSTimeout to the client.

    SocketTimeoutException is thrown in the event that a smaller value is set for SocketTimeout, for example, 2s.

  • The network transmission speed is slow.

    SocketTimeoutException may be thrown if latency is present due to low network transmission speeds, even if the server processing time is unaffected. In this case, check whether there is high traffic volume, insufficient bandwidth, or high network retransmission rates.

  • Garbage collections (GCs), including full GCs, are frequently occurring in Java.

    SocketTimeoutException may be thrown when the program load is high and GCs occur frequently. When a full GC occurs, the application fails to send requests or receive responses. As a result, the time specified in the SDK for SocketTimeout expires, and SocketTimeoutException is thrown.

    In this case, analyze the cause of GCs and resolve them.

Thank you! We've received your feedback.