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

Not a Realm file and Native exception #4176

Closed
KimiChiu opened this issue Feb 13, 2017 · 34 comments
Closed

Not a Realm file and Native exception #4176

KimiChiu opened this issue Feb 13, 2017 · 34 comments

Comments

@KimiChiu
Copy link

KimiChiu commented Feb 13, 2017

Hi,
My crash report keeps receiving these exceptions from some users.
But it never happened on my test device or emulator.
What is the possible cause?

Here's how I write data to Realm:

realm.executeTransactionAsync(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                autoIncrement ++;
                MyRealmObject data = realm.createObject(MyRealmObject.class, id);
                data.setContent( gson.toJson( myData ) ); // String, length range: 7000 ~ 60000
                data.setPage( page ); // int
            }
        });

Here's how I read data from Realm:

RealmQuery<MyRealmObject> query = realm.where(MyRealmObject.class);
query.findAllSorted( MyRealmObject.PAGE, Sort.ASCENDING );

It looks like the user has to remove the app or clear all data to make realm works again.
Is this means the Realm database is crashed?

Firebase Crash Report:

Exception java.lang.RuntimeException: Unable to create application com.ihad.ptt.App: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.ihad.ptt/files/default.realm': Not a Realm file. (Not a Realm file) in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 87 Kind: ACCESS_ERROR.
android.app.ActivityThread.handleBindApplication (ActivityThread.java:5665)
android.app.ActivityThread.-wrap2 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1573)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:173)
android.app.ActivityThread.main (ActivityThread.java:6459)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:938)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:828)
arrow_drop_down
Caused by io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.ihad.ptt/files/default.realm': Not a Realm file. (Not a Realm file) in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 87
io.realm.internal.SharedRealm.nativeGetSharedRealm (SharedRealm.java)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:208)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:186)
io.realm.BaseRealm.compactRealm (BaseRealm.java:586)
io.realm.Realm.compactRealm (Realm.java:1565)
com.ihad.ptt.domain.dao.realm.impl.RealmMigration.init (RealmMigration.java:29)
com.ihad.ptt.App.onCreate (App.java:95)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1037)
android.app.ActivityThread.handleBindApplication (ActivityThread.java:5662)
android.app.ActivityThread.-wrap2 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1573)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:173)
android.app.ActivityThread.main (ActivityThread.java:6459)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:938)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:828)

Native Exception:


Build fingerprint: 'htc/pmeuhl_00709/htc_pmeuhl:6.0.1/MMB29M/801953.5:user/release-keys'
Revision: '0'
ABI: 'arm64'
pid: 13207, tid: 13207, name: com.ihad.ptt >>> com.ihad.ptt <<<
signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7f62978008
x0 0000000000000000 x1 0000007f62908ca0 x2 0000000000000008 x3 0000000000014b00
x4 0000000000ffffff x5 000000000000003f x6 0000000000000040 x7 0000007f62978008
x8 000000000000006d x9 0000000000000000 x10 0000000000000000 x11 0000000000000040
x12 0000000000000010 x13 0000007f84b37a90 x14 000000559a211000 x15 0000007f84b37ad8
x16 0000007f84b30a58 x17 0000000000000000 x18 0000000000000001 x19 000000559a563900
x20 0000000000000000 x21 0000007fdafd3230 x22 0000007fdafd3540 x23 000000559a5634f0
x24 0000007fdafd3640 x25 0000007f62995000 x26 000000559a563700 x27 0000007fdafd3440
x28 000000559a563710 x29 0000007fdafd3160 x30 0000007f627f87d8
sp 0000007fdafd3160 pc 0000007f627b346c pstate 0000000020000000

backtrace:
#00 pc 00000000000e746c /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so
#1 pc 000000000012c7d4 /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so
#2 pc 00000000000a530c /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so
#3 pc 00000000000be754 /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so
#4 pc 00000000000c26ec /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so
#5 pc 00000000000bbcd0 /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so
#6 pc 000000000004d2c0 /data/app/com.ihad.ptt-1/lib/arm64/librealm-jni.so (Java_io_realm_internal_SharedRealm_nativeGetSharedRealm+384)
#7 pc 000000000220c74c /data/app/com.ihad.ptt-1/oat/arm64/base.odex (offset 0x1051000)

Version of Realm and tooling

Realm version(s): 2.2.2

Realm sync feature enabled: no

Android Studio version: IntelliJ IDEA 2016.3.4

Which Android version and device: Android 6.0 HTC 10

@beeender
Copy link
Contributor

Did you use encryption?

@KimiChiu
Copy link
Author

No, I don't.
Forgot the realm configuration.

Realm.init( context ); // ApplicationContext
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
    .schemaVersion( REALM_DATABASE_VERSION ) // Must be bumped when the schema changes
    .migration( this ) // Migration to run instead of throwing an exception
    .build();
Realm.compactRealm( realmConfiguration );
Realm.setDefaultConfiguration(realmConfiguration);

@beeender
Copy link
Contributor

Might be the same problem with compactRealm. Checking ...

@beeender
Copy link
Contributor

realm/realm-core#2426 may fix this.

@kneth
Copy link
Contributor

kneth commented Feb 15, 2017

It is possible to test the fix by using the 2.4.0-SNAPSHOT.

@KimiChiu
Copy link
Author

Thanks!
I'll wait for the release version.

@kneth
Copy link
Contributor

kneth commented Feb 27, 2017

@KimiChiu The release is supposed to come out soon. If it doesn't solved your issue, don't hesitate to either reopen or create new issue.

@KimiChiu
Copy link
Author

Hi,
I'm now using Realm 3.0.0 but still receiving these errors.

Exception java.lang.RuntimeException: Unable to create application com.ihad.ptt.App: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.ihad.ptt/files/default.realm': Bad Realm file header (#1). (Bad Realm file header (#1)) (/data/data/com.ihad.ptt/files/default.realm) in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109 Kind: ACCESS_ERROR.
android.app.ActivityThread.handleBindApplication (ActivityThread.java:4664)
android.app.ActivityThread.access$1500 (ActivityThread.java:156)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1412)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:211)
android.app.ActivityThread.main (ActivityThread.java:5373)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1020)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:815)

Caused by io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.ihad.ptt/files/default.realm': Bad Realm file header (#1). (Bad Realm file header (#1)) (/data/data/com.ihad.ptt/files/default.realm) in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109
io.realm.internal.SharedRealm.nativeGetSharedRealm (SharedRealm.java)
io.realm.internal.SharedRealm. (SharedRealm.java:187)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:229)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:204)
io.realm.BaseRealm.compactRealm (BaseRealm.java:574)
io.realm.Realm.compactRealm (Realm.java:1627)
com.ihad.ptt.domain.dao.realm.impl.RealmMigration.init (RealmMigration.java:29)
com.ihad.ptt.App.onCreate (App.java:97)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1012)
android.app.ActivityThread.handleBindApplication (ActivityThread.java:4661)
android.app.ActivityThread.access$1500 (ActivityThread.java:156)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1412)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:211)
android.app.ActivityThread.main (ActivityThread.java:5373)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1020)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:815)

Another one:

Exception io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109
io.realm.internal.SharedRealm.nativeGetSharedRealm (SharedRealm.java)
io.realm.internal.SharedRealm. (SharedRealm.java:187)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:229)
io.realm.internal.SharedRealm.getInstance (SharedRealm.java:204)
io.realm.BaseRealm.compactRealm (BaseRealm.java:574)
io.realm.Realm.compactRealm (Realm.java:1627)
com.ihad.ptt.domain.dao.realm.impl.RealmMigration.init (RealmMigration.java:29)
com.ihad.ptt.App.onCreate (App.java:97)
android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1015)
android.app.ActivityThread.handleBindApplication (ActivityThread.java:4786)
android.app.ActivityThread.access$1600 (ActivityThread.java:165)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1430)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:150)
android.app.ActivityThread.main (ActivityThread.java:5546)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:792)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:682)

I just remembered that I have another problem before and it's not solved.
That is sometimes the realm initialization is ignored in my Application's onCreate.
So I have to check if it's needed to initialize it again in the Activity's onCreate.

protected RealmHelper getRealmHelper() {
  if (realmHelper == null) {
  realmHelper = RealmHelper.getInstance();
  }

  try {
  if (realm == null) {
  realm = Realm.getDefaultInstance();
  }
  }
  // while Realm.init failed in Application's onCreate
  catch ( IllegalStateException e ){
  new RealmMigration().init(getApplicationContext());
  realm = Realm.getDefaultInstance();
  }

  return realmHelper;
}

The RealmHelper is a singleton class which holds all the instances of the realm operation classes.

Is it caused by the user restores application data by them self?

<application
            android:name=".App"
            android:allowBackup="true"
            android:allowClearUserData="true"
            android:allowTaskReparenting="false"
            android:hardwareAccelerated="true"
            android:icon="@mipmap/ic_launcher_mr"
            android:label="@string/app_name"
            android:largeHeap="true"
            android:theme="@style/AppTheme">
    ...
</application>

Should I just add a try-catch to prevent my application crash?

Version of Realm and tooling

Realm version(s): 3.0.0

Realm sync feature enabled: no

Android Studio version: IntelliJ IDEA 2016.3.4

Which Android version and device:
API 23 HTC 10
API 22 Sony D6503
API 23 HUAWEI GEM-702L
API 23 HTC HTC_M8x

@beeender beeender reopened this Mar 13, 2017
@beeender
Copy link
Contributor

  1. Are you sure the below exception still happens to realm-java 3.0.0? Since it should be fixed. See Realm.compactRealm on external storage throws RealmError: Unrecoverable error. Read-only file system #4140

Exception io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in
/Users/cm/Realm/realm-java/realm/realm-library
...
/src/mainio.realm.BaseRealm.compactRealm (BaseRealm.java:574)

  1. Can you please share the source code of com.ihad.ptt.domain.dao.realm.impl.RealmMigration.init?

  2. Are you using multi-processes in your app?

@KimiChiu
Copy link
Author

  1. Yes, it still happens. Is it possible that it's a legacy from the previous version?

  2. Here's the RealmMIgration.

import android.content.Context;
import com.ihad.ptt.domain.entity.realm.Message;
import com.ihad.ptt.domain.entity.realm.NewTopicCache;
import com.ihad.ptt.domain.entity.realm.People;
import com.ihad.ptt.domain.entity.realm.UserPreference;
import io.realm.*;

import java.util.Date;

public class RealmMigration implements io.realm.RealmMigration {

  // realm 資料庫當前版本
  public static final int REALM_DATABASE_VERSION = 9;

  /**
  * Call this in the UI Thread
  * @param context
  */
  public void init(Context context){
  Realm.init( context );
  RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
  .schemaVersion( REALM_DATABASE_VERSION ) // Must be bumped when the schema changes
  .migration( this ) // Migration to run instead of throwing an exception
// .deleteRealmIfMigrationNeeded()
  .build();

  Realm.compactRealm( realmConfiguration );

  Realm.setDefaultConfiguration(realmConfiguration);
  }

  @Override
  public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
  // DynamicRealm exposes an editable schema
  RealmSchema schema = realm.getSchema();

  // Migrate to version 1: Add a new class.
  // Example:
  // public Person extends RealmObject {
  // private String name;
  // private int age;
  // // getters and setters left out for brevity
  // }
  if (oldVersion == 2) {
  schema.create( UserPreference.TABLE )
  .addField( UserPreference.PRIMARY_KEY, int.class, FieldAttribute.PRIMARY_KEY )
  .addField( UserPreference.NAME , String.class )
  .addField( UserPreference.VALUE, String.class )
  .addField( UserPreference.ENCRYPTED, boolean.class )
  .addField( UserPreference.OWNER, String.class )
  .addField( UserPreference.CREATED_DATE, Date.class )
  .addField( UserPreference.LAST_UPDATE_DATE, Date.class );
  oldVersion++;
  }

  if (oldVersion == 3) {
  schema.create( NewTopicCache.TABLE )
  .addField( NewTopicCache.PRIMARY_KEY, int.class, FieldAttribute.PRIMARY_KEY )
  .addField( NewTopicCache.JSON , String.class );
  oldVersion++;
  oldVersion++;
  }

  if (oldVersion == 5) {
  schema.create( People.TABLE )
  .addField( People.PRIMARY_KEY, int.class, FieldAttribute.PRIMARY_KEY )
  .addField( People.LAST_UPDATE_DATE , long.class )
  .addField( People.USERNAME , String.class )
  .addField( People.NICKNAME , String.class )
  .addField( People.LAST_MESSAGE , String.class );
  oldVersion++;
  }

  if (oldVersion == 6) {
  schema.get( People.TABLE )
  .addField( People.UNREAD_MESSAGES, int.class);
  oldVersion++;
  }

  if (oldVersion == 7) {
  schema.get( People.TABLE )
  .addField( People.OWNER, String.class);
  oldVersion++;
  }

  if (oldVersion == 8) {
  schema.create( Message.TABLE )
  .addField( Message.PRIMARY_KEY, int.class, FieldAttribute.PRIMARY_KEY )
  .addField( Message.CREATED_DATE , Date.class )
  .addField( Message.PEOPLE_ID , int.class )
  .addField( Message.MESSAGE , String.class )
  .addField( Message.MINE , boolean.class )
  .addField( Message.READ_OR_SENT , boolean.class );
  oldVersion++;
  }

  // Migrate to version 2: Add a primary key + object references
  // Example:
  // public Person extends RealmObject {
  // private String name;
  // @PrimaryKey
  // private int age;
  // private Dog favoriteDog;
  // private RealmList<Dog> dogs;
  // // getters and setters left out for brevity
  // }
// if (oldVersion == 1) {
// schema.get("Person")
// .addField("id", long.class, FieldAttribute.PRIMARY_KEY)
// .addRealmObjectField("favoriteDog", schema.get("Dog"))
// .addRealmListField("dogs", schema.get("Dog"));
// oldVersion++;
// }
}
  1. I have a thread handles messaging.
    The instance is created from the MainActivity, but stored in a Service.
    So the user can still receive messages even the Activity has been killed.
    And it uses a Handler to communicate with the main thread.

Add to queue in another thread.

private void sendServiceMessage(int msg){
        if( serviceHandler == null ){
            Timber.i("ServiceHandler is null");
            return;
        }

        MessageBean messageBean = MessageBean.Builder.aMessageBean()
                .withMessage( message.clone() )
                .build();

        Message message = new Message();
        message.what = waterPoloNotification;
        message.obj = messageBean;

        serviceHandler.sendMessage(message);
}

The handler in Service.

private static class ThreadHandler extends Handler {

        private WeakReference<Service> refService;

        public ThreadHandler(Service service) {
            refService = new WeakReference<>(service);
        }

        @Override
        public void handleMessage(Message message) {
            if (refService == null) return;

            Service service = refService.get();

            if (service == null || service.isRestricted() ) return;

            MessageBean messageBean = (MessageBean) message.obj;
            messageBean.setPending(false);

            switch (message.what) {
                ...
                case waterPoloNotification:
                    service.waterPoloNotification(messageBean);
                    break;
                ...
            }

            messageBean.release();
        }
}

Then it'll write the message to Realm database and show the notification.

private void waterPoloNotification(MessageBean messageBean){
        String owner = getUsername();
        if( owner.isEmpty() ) return;

        WaterPoloBean waterPoloBean = messageBean.getMessage();

        switch ( waterPoloBean.getWaterPoloType().getValue() ){
            case WaterPoloType._ON_LINE:{
                onlineNotification( waterPoloBean.getUsername() );
                break;
            }
            
            case WaterPoloType._MESSAGE:{

                boolean chatting = isChatting( waterPoloBean.getUsername() );

                Realm realm = null;
                try{
                    realm = getRealm();

                    getRealmHelper().getMessageService(realm).insert( realm, owner, waterPoloBean.getUsername(),
                            waterPoloBean.getMessage(), chatting, false );
                }
                finally {
                    if( realm != null ){
                        realm.close();
                    }
                }

                if( !chatting ) {
                    messageNotification(waterPoloBean.getUsername(), waterPoloBean.getMessage());
                }
                break;
            }
        }
}

The getRealm().

protected Realm getRealm(){

        try {
            return Realm.getDefaultInstance();
        }
        // while Realm.init failed in Application's onCreate
        catch ( IllegalStateException e ){
            new RealmMigration().init( getApplicationContext() );

            return Realm.getDefaultInstance();
        }
}

@beeender
Copy link
Contributor

Is your service running in another process? Means do you have something like android: process =":remote" in your manifest file?

@KimiChiu
Copy link
Author

No, I don't have android: process =":remote" in my manifest file.
But this service can use startForeground() if the user wants to.

<service
    android:name=".Service"
    android:exported="false"/>

Another service is for Firebase messaging, but it only uses SQLite.

<service android:name=".MessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

@beeender
Copy link
Contributor

allowBackup = true will enable the adb backup/restore. but I am wondering how many users will do that through adb. What kind of your app is? Is it targeted to developers? If you can share you apk somewhere, i can try to verify my hypothesis. You can send it to help@realm.io if you want to share it privately.

@KimiChiu
Copy link
Author

I just released a new version with allowBackup = false in the AndroidManifest.xml.
This app is targeting to Taiwanese, it doesn't use i18n.
So it's hard to use for you, especially when you do the signup process.
If this new version still has this issue, I will write you a tutorial later to show you how to register on the site.(it has to be done on the PC and use the terminal).
Here's the Google Play link, maybe it can help you understand what it is:
https://play.google.com/store/apps/details?id=com.ihad.ptt&hl=zh_TW

@beeender
Copy link
Contributor

@KimiChiu no worries, i can totally read traditional Chinese :P

@KimiChiu
Copy link
Author

That's awesome. Didn't see that coming.
So you can click the "想註冊?" on the login page to see the tutorial if you want to test it.
If you download the v3.6.1 then it's still using allowBackup = true.

@beeender
Copy link
Contributor

Yes, I will try it and let you know the results.

@beeender
Copy link
Contributor

@mariusboepple is the Realm encrypted in your case?

@mariusboepple
Copy link

Yes, it's encrypted.

@Zhuinden
Copy link
Contributor

Zhuinden commented Mar 21, 2017

@mariusboepple Realm 2.3.2 fixed an issue in Realm-Core related to multi-thread / multi-process access of encrypted Realms

Encrypted realms can end up corrupted if many threads are reading and writing at the same time (#4128).

And Realm-Core also fixed realm/realm-core#2426 (another similar issue)

@beeender
Copy link
Contributor

Yes, as @Zhuinden said, please update to 2.3.2 , it should solve most encryption related crashes.

However, there is a new crash related with encryption reported #4343 and we are working on it.

@KimiChiu
Copy link
Author

It looks like this problem still not be solved.
The apk with allowBackup = false has been released for a week.
And I'm still receiving this error report from new devices.
Sony D2533 API 21
Sony D6653 API 23
But it rarely happens, only three different devices report this issue in this version.
Maybe there's someone trying to do something on a rooted device?
Because one of them sent 39 reports in 3 hours.

@beeender
Copy link
Contributor

@KimiChiu What is the device reports 39 crashes in 3 hours?

@KimiChiu
Copy link
Author

It's a Sony D6653 API 23.

@beeender
Copy link
Contributor

beeender commented Apr 5, 2017

@KimiChiu I have played your apk with my Xiaomi Mi5 for a while, but still not able to reproduce the issue :(
Can you see what is the rom version of Sony D6653 which reports this problem?
How is the recent crash rate about this issue? I doubt #4140 could be related with this which is fixed in v2.3.2. Also please be noticed, if this is caused by a corrupted db file, updating will not fix it unless user clear the data cache (to delete the corrupted db file).

@KimiChiu
Copy link
Author

KimiChiu commented Apr 5, 2017

No, Firebase Crash didn't include the rom version.
The crash rate is always under 0.1%.
9 users report these crashes in 7 days and 23 in 30 days.
I got several reports from two devices recently, Samsung SM-N910U API 23 and Asus ASUS_T00J API 19.
But there's no any user contact to me directly, so I'm not sure whether they have these issues before.
However, I just found that these devices did report these crashes from the previous versions.
Maybe you are right, it is caused by a corrupted database.

@mihirjoshi21
Copy link

This is exactly my case #2984 . Crash reported in less than .1% cases. 13 crashes today out of 19.8K sessions.
Also, the line number is different based on realm versions. The one with line 217 is with realm 3.1.2.

  1. /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109 Kind: ACCESS_ERROR.

  2. Bad Realm file header (#3). in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92 Kind: ACCESS_ERROR.

  3. Bad Realm file header (#3). (Bad Realm file header (#3)) (/data/data/com.conem.app.pocketthesaurus/files/dictionary.realm) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 217 Kind: ACCESS_ERROR.

  4. Bad Realm file header (#3). in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 81

Same crash through ages 😲. I still don't know how to resolve it 😞.

@hmedat
Copy link

hmedat commented Feb 1, 2018

Any updates for this issue?

@Zhuinden
Copy link
Contributor

Zhuinden commented Feb 1, 2018

@hmedat2008 many, so it depends on your Realm version and whether your Realm is encrypted or not and whether you compact Realm

@hmedat
Copy link

hmedat commented Feb 1, 2018

Realm Version: 4.2.0
Realm is encrypted: No

@Zey-Uzh
Copy link

Zey-Uzh commented Jun 6, 2018

I also encountered the same problem in Realm 5.1.0
stacktrace 2018-05-29 05-32 (UTC).log

Сonfiguration:

new RealmConfiguration
                .Builder()
                .name(realmName)
                .schemaVersion(Constants.DB_VERSION)
                .directory(dbDir)
                .encryptionKey(key)
                .migration(MIGRATION)
                .initialData(INIT_REALM_TX)
                .build();

I use several threads to access the database.

@Zhuinden
Copy link
Contributor

Zhuinden commented Jun 6, 2018

What's weird is that i've heard that someone wrapping getInstance() call with synchronized(LOCK) could fix the problem

But that is just heresay I heard like 1.5 years ago

@cmelchior
Copy link
Contributor

Closing due to being outdated. The underlying code has changed quite a lot by now. If this is still a problem feel free to re-open.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 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