Foreword
Encountered an unprecedented bug in the debug project java.net.SocketTimeoutException: connect timed out
Yesterday, I could still access the server interface. Today, it timed out and I can’t get the request.
After several setbacks, I tried all the methods I could try, but it still didn’t work.
Going through hours of information finally solved the problem
Record a handful of bitter tears here
SocketTimeout
java.net.SocketTimeoutException: connect timed out
error is understood as connection timed out
and no result is returned
Reason
It may be one of the following problems, you can try both
First: The firewall of the server is not closed, resulting in
Second: Extending the request time results in
//Read timeout is 60s private static final long READ_TIMEOUT = 60000; //write timeout is 60s private static final long WRITE_TIMEOUT = 60000; //Connection timeout is 60s private static final long CONNECT_TIMEOUT = 60000; OkHttpClient.Builder builder = new OkHttpClient.Builder() .readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS) .writeTimeout(WRITE_TIMEOUT, TimeUnit.MILLISECONDS) .connectTimeout(CONNECT_TIMEOUT, TimeUnit.MILLISECONDS)
The third method: After changing the configuration, the server is not restarted
This method is the solution to my problem
Restart the linux server and restart the redis service
The reason for this may be that the configuration was changed before, there was no restart, and there was still a cache.
client
did not get a response when sending an interface to the server~!
Reasons for caching:
Firewall open ports
There are also changes to the ip configuration in the background, etc.
may cause java.net.SocketTimeoutException: connect timed out
Summary
It’s really annoying that this bug appears and can’t be resolved.
When the problem is solved, the excited hands hammer the table
Indescribable 2021 continue to come on~