google / cronet-transport-for-okhttp

This package allows OkHttp and Retrofit users to use Cronet as their transport layer, benefiting from features like QUIC/HTTP3 support or connection migration.
Apache License 2.0
452 stars 34 forks source link

Cronet request lifecycle not triggerred as expected when using apollographql/apollo-kotlin` #37

Open duzinkie opened 4 months ago

duzinkie commented 4 months ago

I've adapted https://github.com/apollographql/apollo-kotlin-tutorial to use https://github.com/google/cronet-transport-for-okhttp (https://github.com/duzinkie/apollo-kotlin-tutorial/tree/duzinkie/cronet-lifecycle-repro) and have observed the app is not functioning correctly when Cronet is used as an http engine.

Let me elaborate: The app built from https://github.com/duzinkie/apollo-kotlin-tutorial/tree/duzinkie/cronet-lifecycle-repro is working fine, until one tries to adjust the logging level of HttpLoggingInterceptor (https://github.com/duzinkie/apollo-kotlin-tutorial/commit/9b3e58ab1dbdb9e2a3151a43e3cdb44531e5b079#diff-518bd35be782210b23f518eaf618c538f99e9f33a81f6b518ccb053b4315eff1R94) - when that happens 2 distinct failure modes occur, depending on whether http batching is enabled.

  1. if batching is enabled: https://github.com/duzinkie/apollo-kotlin-tutorial/commit/9b3e58ab1d - cronet engine does not call the method attached to it in the request finished listener in https://github.com/duzinkie/apollo-kotlin-tutorial/commit/9b3e58ab1dbdb9e2a3151a43e3cdb44531e5b079#diff-518bd35be782210b23f518eaf618c538f99e9f33a81f6b518ccb053b4315eff1R48
  2. if batching is not enabled - all the requests are considered cancelled (although from the UI point of view - everything seems to be functioning just fine (app is responsive, renders fetched data etc)

Steps to reproduce the behavior

  1. Clone https://github.com/duzinkie/apollo-kotlin-tutorial/tree/duzinkie/cronet-lifecycle-repro
  2. Build the app, interact with it, observe it's working fine, and logs contain GQL calls as well as cronet request finished: 0 lines from the cronet http engine (indicating requests are finishing just fine)
  3. Adjust Apollo.kt file in the cloned project: a. change the logging level of HttpLoggingInterceptor to BASIC b. disable httpBatching
  4. Observe the app behavior and logs in both 3a and 3b cases:
    • in 3a - cronet request finished messages are absent and the app hangs after a few interactions
    • in 3b - all requests are marked as cancalled (as indicated by cronet request finished: 2 log messages

Side-notes: