I am building an android app that makes calls to an HTTP/REST api.
I have self signed a certificate for testing and added it to my phones trust store.
I have run into a very strange issue where I will receive the following exception:
java.net.SocketTimeoutException: Read timed out
at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:705)
...
I am at a total loss as to how or why this is happening.
Important notes:
- This happens randomly, comes back after lots of request but sometimes goes away for a day or two.
- I cannot reliably reproduce the issue.
- I have adjusted the timeout settings with no results.
- The issue outlives the life-cycle of the application. Restarting the app has no effect, although it seems to resolve itself within 5 mins.
- If I am using a cookie store, removing it seems to resolve the issue temporally. If I am not using a cookie store, a new instance of the HttpClient needs to be created (as cookies persist temporally with the instance of the HttpClient)
- It is not a DNS issue as I can resolve the endpoint (as I have another app that uses the same endpoint and the same crt).
- I am using the AsyncHttp library for android, but the issue still happens outside of using that library.
- I have tried another device with another version of android (no luck).
Interesting things I have tried:
- I created a new AsyncHttp instance, made a request (without setting the cookiestore) and successfully received a response. Then the app creates another AsyncHttp instance with the cookie store and the issue persists. Even outside the app life-cycle, the first (non cookied) request will work, but the second will not.
- I tired turning off tcp_timestamp (temporally via the file in proc). No change.
If anyone has some idea or experience with a similar issue, please let me know.