Fatal exception: concurrent modification exception
java.util.ArrayList$Itr.next (ArrayList.java:860) net.gotev.cookiestore.SharedPreferencesCookieStore.add (SharedPreferencesCookieStore.kt:107) java.net.CookieManager.put (CookieManager.java:360) net.gotev.cookiestore.WebKitSyncCookieManager.put (WebKitSyncCookieManager.kt:37)
could you please give more context and steps to reproduce?
Happens in prod after upgrade to okhttp5.0-alpha10. not able to reproduce locally
please keep using latest okhttp 4.x. OkHttp 5 is not supported yet.
Any plans to support it? We had to use fastfallback feature which is available in okhttp 5.0
you're welcome to contribute with a PR
Hey this happens in older okhttp versions as well. Can you please provide a fix for concurrent modification exception
What version are you using? Never experienced this personally, so as I asked initially, more context and steps to reproduce are needed to debug this, which needs to be replicated first. A test would be awesome and you're welcome to open a PR. As a quick check, ensure your code is not reading and accessing cookies from more than one thread and if so, consider synchronizing access. From what I see, the exception gets thrown from java.net.CookieManager which is JVM standard library.
We are using 4.9.1. We are not able to reproduce it locally. Was thinking will it help if we switch to concurrent hashmap like below?
internal val uriIndex = ConcurrentHashMap<URI, MutableList<HttpCookie>>()
Hey @gotev can we replace linkedhasmap to concurrentHashmap? It seems be thread safe
So, are you using 4.9.1 with cookie store 1.5.0?
From what I see, that snippet you posted is from the InMemoryCookieStore, but the posted stack trace at the beginning of the thread is not referring to it, but to java.net.CookieManager so I'm not getting the correlation between the two without further evidence, given also that InMemoryCookieStore has locked reads and writes.