-
Notifications
You must be signed in to change notification settings - Fork 545
ConcurrentModificationException in RequestProcessor #91
Comments
When does the exception raise ? |
We are open to any enhancement. Your proposal could be interesting but is vague. We can't reproduce that bug until you tell more about conditions to reproduce it. |
I also get this issue if I modify the method SpiceArrayAdapter.ThumbnailAsynTask.doInBackground like so and have 6 threads in the service:
So, I guess maybe you could reproduce it with the robospice-sample-ui-spicelist. I would have tried, but my modifications of robospice-ui-spicelist extension maybe have a sideeffect, so it would be a hassle for me to try. I have a patchfile with a proposed modification of RequestProcessor to use ConcurrentHashMap and my own version of ConcurrentHashSet (as listRequestListenerForThisRequest needs to be a set apparently and there is no concurrent version of HashSet in the Collections-framework), how can I send the patchfile to you for testing without going through the hassle ov having to setup a branch for a pull request? |
I need time to think about this issue. Thanx for sharing your ideas and 2013/5/15 StingerAJ [email protected]
Stéphane NICOLAS, |
I also got the same issue I do the network call 5 times with the timer delay per 6 sec. This exception doesn't constantly raise, but it happens at most time. Can you take a look at this issue? |
Hi all, Stinger, sorry for that late answer, but I would be pleased to get your Can you create a gist maybe ? Stéphane 2013/6/18 Prildy [email protected]
Stéphane NICOLAS, |
Oh, and I think there a git button directly close to files in the new git Stéphane 2013/6/22 Stéphane Nicolas [email protected]
Stéphane NICOLAS, |
@stephanenicolas I seem to be getting this now using 1.4.8.
Is there any fix? |
We will fix this. It's really a priority issue. Nevertheless, I don't have Stéphane 2013/10/24 AndyFrench [email protected]
Stéphane NICOLAS, |
Hi, I am using 1.4.9 and getting the same exception at DefaultRequestListenerNotifier.java line 168. |
Hello, I'm also using 1.4.9 and getting: java.util.ConcurrentModificationException If I look into the source code I see an iterating:
==> The variable spiceServiceListenerList is defined as a sychronized list. ==> If you look into the implementation of a sychronized list all public methods are synchronized against a mutux. But the iterator itself is NOT synchronized. ==> So I think that any access of such a list using an iterator has to be synchronized as well because while iterating over a synchronized list the list could be motified from any other thread because the access from outside is not globally synchronized. Hope you find an appropriate solution! Cheers, Dirk |
I haven't looked at the code in quite a long time but if the spice service listeners are modified at runtime then yes. However,I'm sure originally they were only to be added once within the constructor of the Spice service as the listeners were designed originally to last the full life span of the object. Those listeners shouldn't necessarily be modified as part of an Activity Life cycle. I don't know if that is still true or not. Andrew deisold [email protected] wrote:
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
The previous examples were from the Default notifier which again I don't understand as it has (last time of looking) a synchronise around it which would be the solution if not there already Andrew Clark [email protected] wrote:
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
Hi, thanks a lot for your quick reply. Obviously the DefaultRequestListenerNotifier uses a synchronized block around the itereration of the list and the SpiceServiceListenerNotifier doesn't. Do you if the robospice team could provide a fix for that soon? We need to go productive within 2 weeks.... |
But do you actually add and remove spice s Service listeners at runtime? If so then for what purpose? deisold [email protected] wrote:
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
What do you mean by at runtime? We have some activities and each of them instantiates a SpiceManager which itself instantiates a SpiceServiceConnection which adds some spice service listeners in onServiceConnected at runtime. |
Yes thanks. I'll have to look sometime at how robospice now works with them. I'm sure the last time I saw them you couldn't remove them. I'll have to check it out. However, this can only be done at evenings and weekends as I work on other stuff during the day. deisold [email protected] wrote:
Sent from my Android phone with K-9 Mail. Please excuse my brevity. |
@stephanenicolas if you are releasing soon for the next RS I believe there could be a simple change in SpiceServiceListenerNotifier for this the last time I looked. By adding as specified above the synchronized around the list iterator. I'll look again to confirm that this is modifiable multiple times but it would be good to add this simple change anyway for release. |
Sorry for the long delay to answer that thread. I just added @softwaremaverick 's changes to RS. All tests seem to pass locally (even if Travis still has some pain on some tests). I am deploying a new snapshot right now. Does one of you wanna try it ? I could release today if receive a go from one of you. Thanks @softwaremaverick, @deisold , @siyamed and @ffgiraldez for finding and patching the bug. |
Hello, I'm using 1.4.12. I do the network call many times and I'm getting: E/AndroidRuntime(4234): java.util.ConcurrentModificationException Thanks |
Can you try our 1.4.13 snapshots and see problem persists ? Thx, 2014-07-01 15:54 GMT+02:00 sayah-y [email protected]:
|
I'm having the same issue as sayah-y. 1.4.13 is not on maven. Will it be available there at some point? Thnx. |
Hi escarti, 1.4.13 is planned to be released soon. We just have one feature branch to Other contributors are working on it. Look at the RS wiki, you will find how to use the 1.4.13 snapshots. Stephane
|
Hi Stephane, thanks for the info, I managed to use the 1.4.13-SNAPSHOT but there are serveral things:
Looking at the code synchronized (listeners) { My guess is that you are synchronizing the Set<RequestListener> listeners but not the RequestListener inside it. I think adding synchronized (listeners) { will solve the problem, but I might be wrong and I didn't have the chance to test it. Hope to be of some help. Thanks for the amazing work! Cheers, |
You also need to upgrade to 1.4.13-SNASPHOT version of RS ! :) 2014-07-07 17:49 GMT+02:00 escarti [email protected]:
|
I mean, not only to add the snapshot repo. 2014-07-07 18:19 GMT+02:00 Stéphane NICOLAS [email protected]:
|
Of course I upgraded. I used:
Cheers, |
Hi Stéphane, I did a project clean and a gradle sync so I assume that the 1.4.13-snapshot is the new one. With an exception breakpoint I saw that the listeners collection has just one item and that item is created in here: spiceManager.execute(postOfferClick, "offer_click", DurationInMillis.ALWAYS_EXPIRED, new PostOfferClickRequestListener()); The full stack trace is: 07-08 12:46:12.448 22861-22861/net.appbounty.android E/AndroidRuntime﹕ FATAL EXCEPTION: main |
Could you check the class of the set of listeners inside the runnable ? I wonder if it is truly a synchronized set and if so, the bug is somewhere Thx for all your efforts, we will a special 1.4.13 for you when it works Stéphane
|
BTW, If you could find which OTHER thread is modifying the listener set while S.
|
Hi Stéphane, after:
I haven't experience the crash for quite some time. Sadly I cannot guarantee that it's not there since I cannot reproduce it, but so far so good. I tried to reproduce the error on debug mode for 45 minutes and didn't happen. Thanks a lot for your support and if I experience it again I will send you the thread causing the issue and as much info as I possibly can. Cheers, |
Ahhhhh :) I was really wondering what else could cause the bug. Nice ! Thx for your continuous feedback and testing. Stéphane 2014-07-08 16:10 GMT+02:00 escarti [email protected]:
|
So this bug is solved in 1.4.13 and its snapshot. |
Yes, my guess is that it needed a clean and after that it used the second version of the snapshot. So to sum up: Your latest 1.4.13-snapshot seems to be the cure :) Thanx! This bug was causing me a lot of headaches! |
Hi Stéphane, I'm sorry to bring bad news again, but the bug re-appeared. I gathered some new info that might help. The error apparently appears when I do 2 times the same API call from different locations. I call my API call from a background service and from a fragment. The exact point where the exception is thrown is HashMapEntry<K, V> nextEntry() { the expectedModCount is 2 whereas the modCount is 3 I will send you the full Thread export and a screenshot of the variables. Hopefully it will help. Cheers, |
Nuts ! ;) I look at the screenshot. 2014-07-09 10:59 GMT+02:00 escarti [email protected]:
|
I implemented a workaround and now I have a "lock" and manually synchronize the api calls to ensure that only one either the service or the fragment are using robospice. So far so good. If you need more info let me know. |
Yes I do. I really don't get it. 2014-07-09 15:53 GMT+02:00 escarti [email protected]:
|
Since I now know what is causing it I managed to reproduce it pretty consistently. I got the service performing a GET Api call every second and I can force the fragment to do an api call on click. In this way I manage to get the crash pretty consistently. How should we proceed? Skype and screen share? |
On which time zone are you ? Really, I can't find anything that could explain this bug.. 2014-07-09 16:38 GMT+02:00 escarti [email protected]:
|
Eduardo and I could finally find the cause of the problem. If you get this exception, it is highly probable that you are either :
from within a request listener's callback method. And you simply can't do this. That's not an RS design problem but more a limitation of java language itself : while iterating through the synchronized set of listeners associated to a request, this set of listeners can't be modified. A workaround could have been to use an Note that a FAQ entry has been added on this matter. |
I noticed that in the SpiceManager the set of listeners is not always syncrhonised. Not sure if that's the cause of the spice manager issue you're seeing Stephan. There are various places where there's a Map of request/listeners, eg.
In various locations it checks whether the list of listeners is null or not, if true it creates it. This happens in Request Processor and Spice Manager. Typically it creates it with a synchronized set, eg. Request Processor addRequest
Spice Manager onRequestAggregated
Whilst SpiceManager addRequest doesn't....
Which is called from
The SpiceManager seems to send this set of listeners to the service in
Although what I'm seeing in the Spice Service at that time is that it simply does an addAll on the listeners. Unless a different implementation does something else. |
Thx @softwaremaverick , but that is exactly what my last commit changes ;) And you're perfectly right, that caused the bug. This plus the explanation given in my last comment. |
I have BroadcastReceiver. I'm calling start of spiceManager in onReceive method: |
Yeah you should do very little in a broadcast receiver. I recommend sending the intent to a service to do further processing On 20 August 2014 13:06:41 BST, nugmanovagulnaz [email protected] wrote:
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
I guess that from a broadcast receiver you don't expect to do something in Stéphane 2014-08-20 13:13 GMT-04:00 softwaremaverick [email protected]:
|
Well, i created IntentService that handles my broadcastReceivers result. |
IntentService is almost the same as broadcast receiver, a simple life Stéphane 2014-08-21 7:38 GMT-04:00 nugmanovagulnaz [email protected]:
|
When i get data from network i want to send another broadcast with this data and it's all. |
Sounds like you need a full service to me! Or! And this is untested but potentially going to work, you could create a spice service with a custom (and I can't remember what I called it) oh... Notifier? As in you could create a custom result notifier which sent the result as a broadcast. The notifiers run in a non ui thread so you don't need to worry about them affecting ui. On 21 August 2014 19:14:44 BST, nugmanovagulnaz [email protected] wrote:
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
What do you mean under a full service? android.app.Service? Service hasn't got onStop() too |
Hi All, Any news about the issue #91? I'm using the version 1.4.13 and it still has the problem: E/AndroidRuntime(9608): FATAL EXCEPTION: main Could you someone help me? Any patch to fix it? Many thanks, |
Please, see FAQ entry about this exception. Chances are it comes from your code (trying to modify the list of listeners during the call back. For instance by stopping the spice manager). |
using a SpiceService with 4 theads some times i get a ConcurrentModificationException
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:796)
at java.util.HashMap$KeyIterator.next(HashMap.java:823)
at com.octo.android.robospice.request.RequestProcessor$ResultRunnable.run(RequestProcessor.java:451)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Can robospice use ConcurrentHashMap?
The text was updated successfully, but these errors were encountered: