square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.88k stars 9.16k forks source link

Use @Streaming on slow internet connection causes packets to be received later and later #7224

Closed JackoxD closed 2 years ago

JackoxD commented 2 years ago

When tou set internet connection on devide to GPRS you has not be able to download a large file (20mb) from server. Packets are receiving later and later (image below) until SocketTimeoutException.

Important you need to set on emulotor settings internet speed to GPRS I've been uploaded a large file to a server and created a test: https://gist.github.com/JackoxD/8f85155ae4c9c05d30ca0ec65c784d2b

java.net.SocketTimeoutException: timeout
        at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.kt:677)
        at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.kt:686)
        at okhttp3.internal.http2.Http2Stream$FramingSource.read(Http2Stream.kt:382)
        at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.kt:276)
        at okio.RealBufferedSource.read(RealBufferedSource.kt:189)
        at okio.ForwardingSource.read(ForwardingSource.kt:29)
        at retrofit2.OkHttpCall$ExceptionCatchingResponseBody$1.read(OkHttpCall.java:314)
        at okio.RealBufferedSource.request(RealBufferedSource.kt:206)
        at okio.RealBufferedSource.require(RealBufferedSource.kt:199)
        at okio.RealBufferedSource.readByte(RealBufferedSource.kt:209)
        at com.examplePackage.actualizationFeature.data.repositories.ActualizationRepositoryImpl.saveFile(ActualizationRepositoryImpl.java:148)
        at com.examplePackage.actualizationFeature.data.repositories.ActualizationRepositoryImpl.save(ActualizationRepositoryImpl.java:117)
        at com.examplePackage.actualizationFeature.domain.usescases.DownloadActualizationUseCase.lambda$invoke$1$com-examplePackage-actualizationFeature-domain-usescases-DownloadActualizationUseCase(DownloadActualizationUseCase.java:43)
        at com.examplePackage.actualizationFeature.domain.usescases.DownloadActualizationUseCase$$ExternalSyntheticLambda7.call(Unknown Source:4)
        at io.reactivex.rxjava3.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:43)
        at io.reactivex.rxjava3.core.Single.subscribe(Single.java:4813)
        at io.reactivex.rxjava3.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
        at io.reactivex.rxjava3.core.Scheduler$DisposeTask.run(Scheduler.java:644)
        at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
        at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

image

JakeWharton commented 2 years ago

This is happening many layers below Retrofit and Retrofit has no control over this. I will transfer the issue to OkHttp, but I'm not sure they'll be able to do much here either.

When I ran a trimmed down version of the test it ran for 18 minutes before throwing an EOFException.

Test is here:

public final class Issue3721Test {
  @Test
  public void test() throws Exception {
    OkHttpClient okHttp = new OkHttpClient.Builder()
      .readTimeout(2, TimeUnit.MINUTES)
      .build();
    Call call = okHttp.newCall(new Request.Builder().url("https://aclas.pimka.net/test.bin").build());
    int size = call.execute().body().source().readByteString().size();
    assertEquals(24210616, size);
  }
}

This was from running on an API 30 emulator with network set to GRPS.

yschimke commented 2 years ago

Dupe of https://github.com/square/okhttp/issues/7215 ?