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

Crash on android 12 on take backup of database #6028

Closed
AsifAliJohari opened this issue Nov 12, 2022 · 7 comments
Closed

Crash on android 12 on take backup of database #6028

AsifAliJohari opened this issue Nov 12, 2022 · 7 comments
Assignees

Comments

@AsifAliJohari
Copy link

AsifAliJohari commented Nov 12, 2022

SDK and version

SDK : java kotlin ? (Cocoa, Java, etc)
Version: 10.9.0

Observations

  • How frequent do the crash occur?
  • When i click on create backup on android 12 with no new change in code which already tested on android 10 it crash
  • Does it happen in production or during dev/test?
  • development
  • Can the crash be reproduced by you?
  • yes
  • Can you provide instructions for how we can reproduce it?

Crash log / stacktrace

/tmp/realm-java/realm/realm-library/src/main/cpp/realm-core/src/realm/util/file.cpp:1028: [realm-core-11.7.0] Assertion failed: r == 0 && "File::unlock()" with (r, (*__errno())) = [-1, 38]
!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
2022-11-12 12:09:24.070 13729-13729 libc myapp A Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 13729 (myapp), pid 13729 (myapp)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A Cmdline: myapp
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A pid: 13729, tid: 13729, name: myapp >>> myapp <<<
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #1 pc 00000000006391f4 /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!librealm-jni.so (BuildId: 9dec3713d9a47b404a31a57c3c82d771d45b946e)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #2 pc 00000000006392c8 /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!librealm-jni.so (BuildId: 9dec3713d9a47b404a31a57c3c82d771d45b946e)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #3 pc 000000000063967c /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!librealm-jni.so (BuildId: 9dec3713d9a47b404a31a57c3c82d771d45b946e)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #4 pc 00000000006283e8 /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!librealm-jni.so (BuildId: 9dec3713d9a47b404a31a57c3c82d771d45b946e)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #5 pc 00000000006264b4 /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!librealm-jni.so (BuildId: 9dec3713d9a47b404a31a57c3c82d771d45b946e)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #6 pc 0000000000565704 /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!librealm-jni.so (BuildId: 9dec3713d9a47b404a31a57c3c82d771d45b946e)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #7 pc 000000000041e9c4 /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!librealm-jni.so (BuildId: 9dec3713d9a47b404a31a57c3c82d771d45b946e)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #8 pc 000000000039c22c /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!librealm-jni.so (Java_io_realm_internal_OsSharedRealm_nativeWriteCopy+116) (BuildId: 9dec3713d9a47b404a31a57c3c82d771d45b946e)
2022-11-12 12:09:25.130 13962-13962 DEBUG pid-13962 A #15 pc 000000000049998a [anon:dalvik-classes.dex extracted in memory from /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk] (io.realm.internal.OsSharedRealm.writeCopy+78)
2022-11-12 12:09:25.131 13962-13962 DEBUG pid-13962 A #21 pc 00000000004d2264 [anon:dalvik-classes19.dex extracted in memory from /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!classes19.dex] (io.realm.BaseRealm.writeCopyTo+16)
2022-11-12 12:09:25.131 13962-13962 DEBUG pid-13962 A #27 pc 00000000004f3010 [anon:dalvik-classes19.dex extracted in memory from /data/app/~~J2AbeBBneUl9OgNjEY3RaA==/myapp-rOsSiFXlvV9Mex_xdgaLjQ==/base.apk!classes19.dex] (io.realm.Realm.writeCopyTo+0)
2022-11-12 12:09:25.131 13962-13962 DEBUG pid-13962 A #33 pc 0000000000005e6a /data/data/myapp/code_cache/.overlay/base.apk/classes7.dex (myapp.app.data.local.db.RealmBackupRestore.backup+266)
2022-11-12 12:09:25.131 13962-13962 DEBUG pid-13962 A #39 pc 000000000000e48a /data/data/myapp/code_cache/.overlay/base.apk/classes8.dex (myapp.app.ui.other.MoreFragment.onViewCreated$lambda-11+50)
2022-11-12 12:09:25.131 13962-13962 DEBUG pid-13962 A #42 pc 000000000000d6c4 /data/data/myapp/code_cache/.overlay/base.apk/classes8.dex myapp.app.ui.other.MoreFragment.$r8$lambda$eTiY7XCYZA0pIvBO0CbKvojI6Pk+0)
2022-11-12 12:09:25.131 13962-13962 DEBUG pid-13962 A #45 pc 000000000000cad4 /data/data/myapp/code_cache/.overlay/base.apk/classes8.dex (myapp.app.ui.other.MoreFragment$$ExternalSyntheticLambda9.onClick+8)

Steps & Code to Reproduce

fun backup(UserIDnumber: String?) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "realm$realm")
Log.d(TAG, "Realm.getDefaultInstance()" + Realm.getDefaultInstance())
}
var exportRealmFile: File? = null
// File exportRealmPATH = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
val exportRealmPATH =
File("${if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) context.externalMediaDirs.firstOrNull()?.path?: context.getExternalFilesDir(null) else Environment.getExternalStorageDirectory().path}/myapp/Backup/")

  // File(Environment.getExternalStorageDirectory().path + "/myapp/Backup/")
    if (!exportRealmPATH.exists()) {
        exportRealmPATH.mkdirs()
    }
    val exportRealmFileName = "myapp.realm"
    try {
        val compressFiles = arrayOfNulls<String>(2)


        // create a backup file
        exportRealmFile = File(exportRealmPATH, exportRealmFileName)

        // if backup file already exists, delete it
        exportRealmFile.delete()

        // copy current realm to backup file
        realm.writeCopyTo(exportRealmFile)
        val gpxfile = File(exportRealmPATH, "config")
        val writer = FileWriter(gpxfile)
        writer.append(UserIDnumber)
        writer.flush()
        writer.close()
        compressFiles[0] = "$exportRealmPATH/myapp.realm"
        compressFiles[1] = "$exportRealmPATH/config"
        val ts =
            exportRealmPATH.toString() + "/" + (System.currentTimeMillis() / 1000) + "_backup.myapp"
        zip(compressFiles, ts, File(compressFiles[0]), File(compressFiles[1]))
    } catch (e: Exception) {
        e.printStackTrace()
    }
    val msg = "File exported to Path: " + exportRealmPATH.path
    Log.d(TAG, msg)
    realm.close()
}
@ironage
Copy link
Contributor

ironage commented Nov 14, 2022

Hi @AsifAliJohari thanks for reporting this. What kind of file system is the external storage directory located on? Does the code work if you use a different file system?
@cmelchior do you see any problems in the provided code sample?

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Nov 14, 2022
@cmelchior
Copy link
Contributor

@AsifAliJohari It looks like you are hitting the new security restrictions introduced in Android 11 which require you to use the Scoped Storage API's: https://developer.android.com/about/versions/11/privacy/storage

These API's prevent Realm from opening and using Realm files on external storage directly.

This was also reported here #4777 and here #5107

@AsifAliJohari
Copy link
Author

AsifAliJohari commented Nov 14, 2022 via email

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Nov 14, 2022
@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label Nov 17, 2022
@AsifAliJohari AsifAliJohari reopened this Nov 17, 2022
@jedelbo
Copy link
Contributor

jedelbo commented Nov 23, 2022

It seems like there is little we can do to solve this. @AsifAliJohari not sure why you closed and reopened. Do you have further questions before we close this issue?

@AsifAliJohari
Copy link
Author

AsifAliJohari commented Nov 24, 2022 via email

@AsifAliJohari
Copy link
Author

AsifAliJohari commented Nov 24, 2022 via email

@jedelbo
Copy link
Contributor

jedelbo commented Nov 25, 2022

Ok, I will then close this issue. You can open another, if you have a different problem.

@jedelbo jedelbo closed this as completed Nov 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants