Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal exception: concurrent modification exception #37

Open
hbj508 opened this issue Nov 16, 2023 · 10 comments
Open

Fatal exception: concurrent modification exception #37

hbj508 opened this issue Nov 16, 2023 · 10 comments

Comments

@hbj508
Copy link

hbj508 commented Nov 16, 2023

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)

@gotev
Copy link
Owner

gotev commented Nov 16, 2023

could you please give more context and steps to reproduce?

@hbj508
Copy link
Author

hbj508 commented Nov 16, 2023

Happens in prod after upgrade to okhttp5.0-alpha10. not able to reproduce locally

@gotev
Copy link
Owner

gotev commented Nov 16, 2023

please keep using latest okhttp 4.x. OkHttp 5 is not supported yet.

@hbj508
Copy link
Author

hbj508 commented Nov 16, 2023

Any plans to support it? We had to use fastfallback feature which is available in okhttp 5.0

@gotev
Copy link
Owner

gotev commented Nov 16, 2023

you're welcome to contribute with a PR

@hbj508
Copy link
Author

hbj508 commented Nov 17, 2023

Hey this happens in older okhttp versions as well. Can you please provide a fix for concurrent modification exception

@gotev
Copy link
Owner

gotev commented Nov 18, 2023

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.

@hbj508
Copy link
Author

hbj508 commented Nov 24, 2023

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>>()

@hbj508
Copy link
Author

hbj508 commented Feb 20, 2024

Hey @gotev can we replace linkedhasmap to concurrentHashmap? It seems be thread safe

@gotev
Copy link
Owner

gotev commented Feb 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants