klippa-app/nativescript-http

[ANDROID] - Fatal Exception: java.util.ConcurrentModificationException

mapo80 opened this issue · 4 comments

On my app I've this crash on Crashlytics:

Fatal Exception: java.util.ConcurrentModificationException
       at java.util.HashMap$HashIterator.nextNode(HashMap.java:1441)
       at java.util.HashMap$KeyIterator.next(HashMap.java:1465)
       at com.klippa.NativeScriptHTTP.SetCookieCache$SetCookieCacheIterator.next(SetCookieCache.java:51)
       at com.klippa.NativeScriptHTTP.SetCookieCache$SetCookieCacheIterator.next(SetCookieCache.java:36)
       at com.klippa.NativeScriptHTTP.MemoryCookieJar.loadForRequest(MemoryCookieJar.java:29)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:74)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:74)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
       at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:197)
       at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:502)
       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)

Maybe is not thread safe? How to prevent to crash?

Which platform(s) does your issue occur on?

Android

Please, provide the following version numbers that your issue occurs with:

  • CLI: 6.7.4
  • Cross-platform modules: (check the 'version' attribute in the
    6.5.4
  • Runtime(s): 6.5.0
  • Plugin(s):
    @klippa/nativescript-http: 1.3.1

It might be that the cookiestore isn't thread safe. Do you have a small sample to reproduce?
I think the best solution would be to add a mutex to de cookiestore actions.

Sorry, I don’t have a sample to reproduce issue.
How can I help you to fix this issue?

Thanks

I tried to reproduce this issue quite a bit, by doing a lot of requests to two different domains at the same domain. Both request would send 10 cookies back that would be invalid on the next request, so they would removed by the cookiejar.
I thought that might trigger this bug as it would cause a lot of mutations/reads on the cookiejar at the same time, sadly I could not reproduce it and all requests would be executed successfully all the time.

Is this something you see often? If so, can you give me more details about how you use the plugin?

I found this issue only 3 times till now on 3 different devices and SO. I'll contact you if I have more news.
Thanks.