realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Crash while removing objects in forEach block #7792

Closed Khudoyshukur closed 1 year ago

Khudoyshukur commented 1 year ago

PluginVersion: 10.13.0

I am getting crash here in production: image

Here the code block: image

ExecureRealmTransaction has a mutex. So, no other transaction disturb current transaction. image

I am guessing that the crash is coming from line:32 because of ConcurrentModification. What should I use in this case? .deleteAllFromRealm() ? Or should I reverse-iterate?

Similar issue: https://github.com/realm/realm-java/issues/2660

clementetb commented 1 year ago

I am unable to reproduce the issue. It might have something to do with your code. Would it be possible to share a sample project that causes the issue?

On the other hand, I think that you could use:

Khudoyshukur commented 1 year ago

@clementetb I myself also could not reproduce the crash locally. It is happening with few Samsung Android devices.

  1. executeTransactionAwait? Does it ensure synchonization? For example, one transaction is in progress. And the second transaction should wait.
  2. I will use it.
clementetb commented 1 year ago

No need to ensure synchronization yourself. There can only be one active write transaction per Realm.

Khudoyshukur commented 1 year ago

@clementetb Thank you. I will take your recommendations and further monitor this crash

Khudoyshukur commented 1 year ago

@clementetb I am no more getting the crash reports after the changes. So I am closing the issue