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

Try to fix #4007 #4193

Merged
merged 6 commits into from
Oct 12, 2021
Merged

Try to fix #4007 #4193

merged 6 commits into from
Oct 12, 2021

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Oct 8, 2021

Still crashing from time to time :/

Log is always

D/CleanupSession: Realm instance (4 - 1)
D/CleanupSession: Cleanup: delete session params...
D/CleanupSession: Cleanup: cancel pending works...
D/CleanupSession: Cleanup: clear session data...
D/CleanupSession: Cleanup: clear crypto data...
D/CleanupSession: Cleanup: clear the database keys
D/CleanupSession: Cleanup: release session...
D/CleanupSession: Wait for all Realm instance to be closed (3 - 0)
D/CleanupSession: Waiting 10ms
D/CleanupSession: Wait for all Realm instance to be closed (0 - 0)
D/CleanupSession: Cleanup: clear file system

Whatever the value of TIME_TO_WAIT_MILLIS (tested with 1, 10, 100, 200).

Also other crashes can occur, not all the time...

@github-actions
Copy link

github-actions bot commented Oct 8, 2021

Unit Test Results

  42 files  ±0    42 suites  ±0   44s ⏱️ -2s
  83 tests ±0    83 ✔️ ±0  0 💤 ±0  0 ±0 
220 runs  ±0  220 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit a7ec76b. ± Comparison against base commit 7088e5c.

♻️ This comment has been updated with latest results.

@ariskotsomitopoulos
Copy link
Contributor

Still crashing from time to time :/

Log is always

D/CleanupSession: Realm instance (4 - 1)
D/CleanupSession: Cleanup: delete session params...
D/CleanupSession: Cleanup: cancel pending works...
D/CleanupSession: Cleanup: clear session data...
D/CleanupSession: Cleanup: clear crypto data...
D/CleanupSession: Cleanup: clear the database keys
D/CleanupSession: Cleanup: release session...
D/CleanupSession: Wait for all Realm instance to be closed (3 - 0)
D/CleanupSession: Waiting 10ms
D/CleanupSession: Wait for all Realm instance to be closed (0 - 0)
D/CleanupSession: Cleanup: clear file system

Whatever the value of TIME_TO_WAIT_MILLIS (tested with 1, 10, 100, 200).

Also other crashes can occur, not all the time...

Relative issue

@ouchadam
Copy link
Contributor

TIL from the docs https://docs.mongodb.com/realm-legacy/docs/java/latest/#closing-realms

Realm instances are reference counted—if you call getInstance twice in a thread, you need to call close twice as well. This allows you to implement Runnable classes without having to worry about which thread will execute them: simply start it with getInstance and end it with close.

from the original issue #4007 the stacktrace looks like realm is still closing/has deleted a required file after it initialised the new instance of the database, very odd! 🤔

'/data/user/0/im.vector.app.debug/files/.../crypto_store.realm.lock' does not exist.

@bmarty
Copy link
Member Author

bmarty commented Oct 12, 2021

Actually I think all the Realm instance are closed, then when delete the files, but after that DefaultDownloadKeysForUsers wants to write to the database. Something is not properly cancelled.

@ouchadam
Copy link
Contributor

ouchadam commented Oct 12, 2021

could it be that the wrong realm instance is somehow being used after logout? maybe a singleton somewhere is still referencing the closed instance

Wait for Realm instance to be effectively closed before deleting Realm files
@bmarty bmarty force-pushed the feature/bma/fix_logout_crash branch from b4a345c to 0d85299 Compare October 12, 2021 08:41
@bmarty
Copy link
Member Author

bmarty commented Oct 12, 2021

Looking again at the stacktrace from #4007 , I can see:

at com.zhuinden.monarchy.Monarchy.runTransactionSync(Monarchy.java:164)

Which is called from Monarchy.writeAsync, and from our codebase here

So this commit try to cancel all the pending async request(s).

No crash observed, but I would like to see a log like like this:

W/RealmCryptoStore: Closing RealmCryptoStore, 1 async task(s) cancelled

But I have only seen

W/RealmCryptoStore: Closing RealmCryptoStore, 0 async task(s) cancelled

WDYT?

@@ -379,7 +379,8 @@ internal interface IMXCryptoStore {

fun getOrAddOutgoingSecretShareRequest(secretName: String, recipients: Map<String, List<String>>): OutgoingSecretRequest?

fun saveGossipingEvent(event: Event)
fun saveGossipingEvent(event: Event) = saveGossipingEvents(listOf(event))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

delay(TIME_TO_WAIT_MILLIS)
timeToWaitMillis -= TIME_TO_WAIT_MILLIS
} else {
timeToWaitMillis = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also log when we fail to close all instances in time, would it be helpful for rageshakes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will see the bunch of similar logs and it will be enough

@bmarty bmarty marked this pull request as ready for review October 12, 2021 12:55
@bmarty bmarty enabled auto-merge October 12, 2021 12:55
@bmarty bmarty merged commit 7338982 into develop Oct 12, 2021
@bmarty bmarty deleted the feature/bma/fix_logout_crash branch October 12, 2021 13:19
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

Successfully merging this pull request may close these issues.

4 participants