Kamel-Media / Kamel

Kotlin asynchronous media loading and caching library for Compose.
Apache License 2.0
637 stars 24 forks source link

When an image fails to load, it is retried infinitely and recomposes as fast as possible #9

Closed outadoc closed 2 years ago

outadoc commented 2 years ago

First, thanks for the great lib! I have a single problem with it so far, and here it is 🙂

When an image fails to load (no network, bad URL, any time of error I've tested), the HTTP call is retried as fast as possible without any delay, maxing out the CPU. Additionally, the onFailure block is recomposed every time this happens, since we're throwing a new exception on every cycle.

This might cause a DDOS on the server that is supposed to serve the request, and in my case leads to throttling of the API I'm using.

How to reproduce:

  1. In io.kamel.samples.Gallery, set ItemsCount to 1. This will make it easier to see the problem.
  2. In io.kamel.samples.Utils, break the URL so that it fails to load any image. For example, change picsum.photos to picsum.phtos.
  3. In io.kamel.samples.SampleImage, in the onFailure block, add a log directive such as println(exception).
  4. Run ./gradlew :kamel-samples:run and observe the logs.

What happens:

The log is spammed with java.nio.channels.UnresolvedAddressException as fast as the CPU can handle.

What was expected:

I see a single Exception logged. Alternatively, the image load is retried every N seconds, with N configurable in KamelConfig.

The effect can also be observed on an image with crossfade = true and a loading placeholder, you can see the image fade in and out as fast as it can.

Thanks!

alialbaali commented 2 years ago

This should be fixed in version 0.3.0.

outadoc commented 2 years ago

Thanks for the quick turnaround, seems to work great now! The 1.0.0-beta1 upgrade is welcome as well 🎉