Concurrency crash

Bug #389437 reported by Benoit Garret on 2009-06-19
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fix Released

Bug Description

Tomdroid sometimes crashes with the following stacktrace:

Uncaught handler: thread main exiting due to uncaught exception
at java.util.AbstractList$
at org.tomdroid.NoteCollection.findNoteFromTitle(
at org.tomdroid.ui.Tomdroid.updateNoteListWith(
at org.tomdroid.ui.Tomdroid.access$0(
at org.tomdroid.ui.Tomdroid$1.handleMessage(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(
at dalvik.system.NativeStart.main(Native Method)

I have attached a patch that should fix the crash. This is another quick fix as the notecollection will disappear.

Benoit Garret (benoit.garret) wrote :
Olivier Bilodeau (plaxx) wrote :

Was able to reproduce. I'll test if the fix do any performance regression. If there is no regression or it's not big i'll apply it shortly to main.

Changed in tomdroid:
importance: Undecided → High
milestone: none → 0.2
status: New → Confirmed
Olivier Bilodeau (plaxx) wrote :

Even with the fix, I was able to crash it again at another spot:

E/AndroidRuntime( 5121): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.tomdroid/org.tomdroid.ui.ViewNote}: java.util.ConcurrentModificationException
E/AndroidRuntime( 5121): at
E/AndroidRuntime( 5121): at
E/AndroidRuntime( 5121): at$1800(
E/AndroidRuntime( 5121): at$H.handleMessage(
E/AndroidRuntime( 5121): at android.os.Handler.dispatchMessage(
E/AndroidRuntime( 5121): at android.os.Looper.loop(
E/AndroidRuntime( 5121): at
E/AndroidRuntime( 5121): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5121): at java.lang.reflect.Method.invoke(
E/AndroidRuntime( 5121): at$
E/AndroidRuntime( 5121): at
E/AndroidRuntime( 5121): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5121): Caused by: java.util.ConcurrentModificationException
E/AndroidRuntime( 5121): at java.util.AbstractList$
E/AndroidRuntime( 5121): at org.tomdroid.NoteCollection.buildNoteLinkifyPattern(
E/AndroidRuntime( 5121): at org.tomdroid.ui.ViewNote.showNote(
E/AndroidRuntime( 5121): at org.tomdroid.ui.ViewNote.onCreate(
E/AndroidRuntime( 5121): at
E/AndroidRuntime( 5121): at
E/AndroidRuntime( 5121): ... 11 more

I'll see what I can do about this one.

Benoit Garret (benoit.garret) wrote :

I believe the most simple way to fix this would be to wrap all calls to notecollection with synchronized blocks. This should get us rid of the concurrent modifications issues.

The basic problem here is that the List used to store the notes in the NoceCollection is not thread safe.

Olivier Bilodeau (plaxx) wrote :

Like you said earlier, since we are getting rid of NoteCollection to the profit of a db that should handle all of this better, I'm not putting a lot of effort to make a clean fix.

Attached is my attempt at an ugly fix (warning: I'm no synchronization expert). Since ViewNote is also using findNoteFromTitle(...) I decided to make the method synchronized and dropped your patch.

I also synchronized buildNoteLinkifyPattern() and it did fix the crasher I experienced in comment #3.

I tested performance using the benchmark patch in doc/dev/threading-improvement/ and didn't notice any performance regression. Results added to benchmarks.txt

Can you test the patch and tell me if it fixes yours? I am no longer able to reproduce and not sure if I was ever able to..

Olivier Bilodeau (plaxx) wrote :

Ok, turns out I was able to reproduce your crash quite easily on the emulator. Just by reloading the app while hot (no reinstall) I got the same stacktrace as you did. On my ADP1, I was not able to reproduce your crash.

Anyways, the fix I proposed on comment #5 did work for me on both cases so I applied it to trunk/.

If you can try it and report back here it would be really appreciated since I want to release 0.2.0rc1 soon.

Changed in tomdroid:
status: Confirmed → Fix Committed
Benoit Garret (benoit.garret) wrote :

Can't seem to reproduce it with your fix, it's ok for me.

Olivier Bilodeau (plaxx) wrote :

fix released with 0.2 almost 7 months ago..

Changed in tomdroid:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers