square / retrofit

A type-safe HTTP client for Android and the JVM
https://square.github.io/retrofit/
Apache License 2.0
43.01k stars 7.3k forks source link

Getting frequent D/OkHttp: <-- HTTP FAILED: java.net.SocketTimeoutException: failed to connect to <domain-name>/<ip> (port 8443) from /<ip-source> (port 50810) after 60000ms: isConnected failed: ETIMEDOUT (Connection timed out) #3800

Closed ganeshpadhayay closed 1 year ago

ganeshpadhayay commented 1 year ago

I am getting frequent(one in 10 times average) D/OkHttp: <-- HTTP FAILED: java.net.SocketTimeoutException from my servers and I have set all timeouts(read, write, connect) to 60seconds but I get this exception in 8-10 seconds and there are no hits on my server for these requests.

Some of the previously closed issues(https://github.com/square/okhttp/issues/6486) discuss IPv4 vs IPv6 issues at client and/or server-side but my server supports only IPv4 and I made the client(android device) use IPv4 only still I am receiving this.

Can someone please help here,

Retrofit deps - api "com.squareup.retrofit2:retrofit:2.6.2" api 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2' api "com.squareup.retrofit2:converter-moshi:2.6.2" api "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2" api 'com.squareup.retrofit2:converter-gson:2.7.1' api 'com.squareup.retrofit2:adapter-rxjava2:2.7.1' implementation 'com.squareup.retrofit2:converter-scalars:2.4.0'

OkHttp deps - implementation "com.squareup.okhttp3:okhttp:3.12.0" api 'com.squareup.okhttp3:logging-interceptor:3.12.0' api 'com.squareup.okhttp3:logging-interceptor:4.4.0'

JakeWharton commented 1 year ago

Unfortunately Retrofit has no influence over this and you'll have to seek help elsewhere. Retrofit basically is a fancy way to create OkHttp requests, call enqueue to schedule them, and then parse the OkHttp response. We're not involved in how requests happen or have an influence on that process directly. It's entirely at the OkHttp layer and however you've configured it.

Put another way, if you manually sent the requests that Retrofit makes using OkHttp directly you'd observe the same problem. So Retrofit can't do anything here.