Java.net.SocketTimeoutException: timeout
Con la biblioteca OkHttp
, la aplicación se enfrenta al siguiente problema de SocketTimeoutException
. Si el tamaño de la solicitud es menor, entonces funciona bien (menos de 1 MB). Estoy recibiendo esta excepción en 10 segundos, incluso mi valor de tiempo de espera de socket ( readTimeout
) es mucho mayor. Es consistentemente fallando para una solicitud (tamaño es 1,8 MB). Cuando HttpUrlConnection
una solicitud con HttpUrlConnection
está funcionando bien. ¿Cuál podría ser una posible razón de fracaso?
03-29 12:16:38.997 32066-4018/com.mobile W/System.err: java.net.SocketTimeoutException: timeout 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.Okio$3.newTimeoutException(Okio.java:207) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.AsyncTimeout.exit(AsyncTimeout.java:261) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.AsyncTimeout$1.write(AsyncTimeout.java:158) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:46) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.internal.http.Http1xStream$FixedLengthSink.write(Http1xStream.java:286) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okio.RealBufferedSink.write(RealBufferedSink.java:96) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.RequestBody$2.writeTo(RequestBody.java:96) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:704) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:241) 03-29 12:16:38.997 32066-4018/com.mobile W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at okhttp3.RealCall.execute(RealCall.java:57) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at com.mobizio.api.BaseApi.sendOkHttpRequest(BaseApi.java:81) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at com.mobizio.api.BaseApi.doInBackground(BaseApi.java:45) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at com.mobizio.api.BaseApi.doInBackground(BaseApi.java:30) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:292) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at java.lang.Thread.run(Thread.java:818) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: Caused by: java.net.SocketException: socket is closed 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:759) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at okio.Okio$1.write(Okio.java:80) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: at okio.AsyncTimeout$1.write(AsyncTimeout.java:155) 03-29 12:16:38.998 32066-4018/com.mobile W/System.err: ... 20 more
- ¿Cómo publico datos usando la biblioteca okhttp con el tipo de contenido x-www-form-urlencoded?
- Falló el socket OkHttp3: EMFILE (Demasiados archivos abiertos)
- ¿Cómo obtener la URL redireccionada de OkHttp3?
- Enlace SSL mediante Google Volley
- Retrofit: el servidor devuelve tanto ETag como Cache-Control: max-age = 60. ¿No debería utilizarse la memoria caché si se solicita <60s?
- MultipartBuilder no se puede resolver en okhttp: 3.0.0-RC1
- ¿Cómo enviar post parámetros dinámicamente (o en bucle) en OKHTTP 3.x en android?
- If-None-Match no se pasa en mi solicitud
- OkHttpClient tiene un recuento máximo de reintentos
- "Return response.body (). String ()" está vacío con okhttp3
- Deslizamiento con la integración okhttp3 java.lang.NoClassDefFoundError
- La llamada a la API de Retrofit recibe "HTTP FAILED: java.io.IOException: Cancelled"
- OkHttp y Retrofit, token de actualización con solicitudes concurrentes
Para OkHttp 3 el valor predeterminado para OkHttp es 10 segundos. Puede aumentar el tiempo de espera a 30 segundos.
OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(30, TimeUnit.SECONDS); // connect timeout client.setReadTimeout(30, TimeUnit.SECONDS); // socket timeout
writeTimeout()
ese problema incrementando writeTimeout()
.
Tratar:
OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.connectTimeout(5, TimeUnit.MINUTES) .writeTimeout(5, TimeUnit.MINUTES) .readTimeout(5, TimeUnit.MINUTES); okHttpClient = builder.build();