Kamel-Media / Kamel

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

Null pointer exception in LruCache on iOS #66

Closed DJ-LEE11 closed 10 months ago

DJ-LEE11 commented 11 months ago

Affected platforms

Versions

Crash Info 7CBCA0D1DA9016C4587CDD705

Occurrence location

infoflow 2023-11-01 16-32-55

LinkedHashMap is thread-unsafe.

luca992 commented 11 months ago

Yeah, that's definitely an issue with the LRU Cache. How often does it happen? Do you have a way to reproduce it regularly?

It's not thread safe: see: https://github.com/apollographql/apollo-kotlin/pull/2878 https://github.com/apollographql/apollo-kotlin/issues/2844

looks like using https://github.com/ReactiveCircus/cache4k could be a solution?

DJ-LEE11 commented 11 months ago

This crash happened by chance. Our current solution is to use Ktor provide thread-safe ConcurrentMap to replace LinkedHashMap.

infoflow 2023-11-01 16-10-59
luca992 commented 11 months ago
Screenshot 2023-11-02 at 3 32 32 AM

Making sure we use the same coroutineContext when loading a cached resource might be the issue. Idk have to look into it more.

luca992 commented 11 months ago

but then again I don't think using a suspend there would be ideal 🤔

luca992 commented 10 months ago

https://github.com/touchlab/Stately is another option

luca992 commented 10 months ago

try 0.9.0 lmk if you have any problems. I switch it to being backed by stately's ConcurrentMutableMap