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

Native Crash on RealmObject Update #5808

Closed
bmadaras opened this issue Mar 6, 2018 · 7 comments
Closed

Native Crash on RealmObject Update #5808

bmadaras opened this issue Mar 6, 2018 · 7 comments
Labels

Comments

@bmadaras
Copy link

bmadaras commented Mar 6, 2018

Goal

Update a saved object with a new version from service

Expected Results

Update the current object

Actual Results

03-06 18:59:29.626 10104-10104/com.armssoftware.android A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 10104 (oftware.android)
03-06 18:59:29.784 10416-10416/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-06 18:59:29.784 10416-10416/? A/DEBUG: Build fingerprint: 'google/sdk_gphone_x86/generic_x86:8.0.0/OSR1.170901.056/4497355:userdebug/dev-keys'
03-06 18:59:29.784 10416-10416/? A/DEBUG: Revision: '0'
03-06 18:59:29.784 10416-10416/? A/DEBUG: ABI: 'x86'
03-06 18:59:29.784 10416-10416/? A/DEBUG: pid: 10104, tid: 10104, name: oftware.android >>> com.armssoftware.android <<<
03-06 18:59:29.784 10416-10416/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
03-06 18:59:29.784 10416-10416/? A/DEBUG: Cause: null pointer dereference
03-06 18:59:29.784 10416-10416/? A/DEBUG: eax 00000000 ebx 922f5de4 ecx bfcef948 edx 00000001
03-06 18:59:29.785 10416-10416/? A/DEBUG: esi 00000000 edi 00000000
03-06 18:59:29.785 10416-10416/? A/DEBUG: xcs 00000073 xds 0000007b xes 0000007b xfs 0000003b xss 0000007b
03-06 18:59:29.785 10416-10416/? A/DEBUG: eip 920a4c19 ebp 912b8c0c esp bfcef900 flags 00010297
03-06 18:59:30.027 10416-10416/? A/DEBUG: backtrace:
03-06 18:59:30.027 10416-10416/? A/DEBUG: #00 pc 000e4c19 /data/app/com.armssoftware.android-eOMGXnD93VYA658DwCiaqg==/lib/x86/librealm-jni.so
03-06 18:59:30.027 10416-10416/? A/DEBUG: #1 pc 000e4eb7 /data/app/com.armssoftware.android-eOMGXnD93VYA658DwCiaqg==/lib/x86/librealm-jni.so
03-06 18:59:30.027 10416-10416/? A/DEBUG: #2 pc 001114a7 /data/app/com.armssoftware.android-eOMGXnD93VYA658DwCiaqg==/lib/x86/librealm-jni.so
03-06 18:59:30.027 10416-10416/? A/DEBUG: #3 pc 00111a47 /data/app/com.armssoftware.android-eOMGXnD93VYA658DwCiaqg==/lib/x86/librealm-jni.so
03-06 18:59:30.027 10416-10416/? A/DEBUG: #4 pc 000f69d8 /data/app/com.armssoftware.android-eOMGXnD93VYA658DwCiaqg==/lib/x86/librealm-jni.so
03-06 18:59:30.027 10416-10416/? A/DEBUG: #5 pc 000d6658 /data/app/com.armssoftware.android-eOMGXnD93VYA658DwCiaqg==/lib/x86/librealm-jni.so
03-06 18:59:30.027 10416-10416/? A/DEBUG: #6 pc 00112d49 /data/app/com.armssoftware.android-eOMGXnD93VYA658DwCiaqg==/lib/x86/librealm-jni.so
03-06 18:59:30.027 10416-10416/? A/DEBUG: #7 pc 00112fd6 /data/app/com.armssoftware.android-eOMGXnD93VYA658DwCiaqg==/lib/x86/librealm-jni.so
03-06 18:59:30.027 10416-10416/? A/DEBUG: #8 pc 00014a37 /system/lib/libutils.so (_ZN7android20SimpleLooperCallback11handleEventEiiPv+39)
03-06 18:59:30.027 10416-10416/? A/DEBUG: #9 pc 0001586c /system/lib/libutils.so (_ZN7android6Looper9pollInnerEi+988)
03-06 18:59:30.027 10416-10416/? A/DEBUG: #10 pc 00015406 /system/lib/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+118)
03-06 18:59:30.027 10416-10416/? A/DEBUG: #11 pc 000e4cbb /system/lib/libandroid_runtime.so (_ZN7androidL38android_os_MessageQueue_nativePollOnceEP7_JNIEnvP8_jobjectxi+59)
03-06 18:59:30.027 10416-10416/? A/DEBUG: #12 pc 007b4198 /system/framework/x86/boot-framework.oat (offset 0x5e6000) (android.app.NativeActivity.onWindowFocusChangedNative [DEDUPED]+136)
03-06 18:59:30.027 10416-10416/? A/DEBUG: #13 pc 000756a0 /dev/ashmem/dalvik-jit-code-cache (deleted)
03-06 18:59:30.027 10416-10416/? A/DEBUG: #14 pc 4a292753
03-06 18:59:30.027 10416-10416/? A/DEBUG: #15 pc 0d3fffff /dev/ashmem/dalvik-main space (region space) (deleted)
03-06 18:59:30.027 10416-10416/? A/DEBUG: #16 pc 00d25f9a /system/framework/x86/boot-framework.vdex

Steps & Code to Reproduce

Currently in process of upgrading from version 3.3.2 to 4.3.4

This pattern is in place for many other models and all seem to work without issue so my assumption is that there is something wrong with the model.

Insert the model with some of the properties missing, summary level, then come back and get the full detail of the model and try to update.

Cleared the database and started from scratch.
Modified model to remove list and index.
Tried beginning and then committing a transaction on the realm instance as am currently executing a Realm.Transaction synchronously.

Code Sample

//This is being executed on a background thread
new Runnable() {
            @Override
            public void run() {
final Response<Group> response =
                            api.getGroupDetail(sportId, groupId).execute();

                    Realm realm = SportRealmConfiguration.getSportRealmInstance();
                    if (response.isSuccessful()) {
                        final RosterGroup updatedGroup = response.body();
                            realm.executeTransaction(new Realm.Transaction() {
                                @Override
                                public void execute(final Realm realm) {
                                    realm.insertOrUpdate(updatedGroup);
                                }
                            });

                    }
}
        }

//Model
public class Group extends RealmObject {

    public static final String PK = "groupId";
    public static final String FIELD_SPORT = "sportId";
    public static final String FIELD_TYPE = "type";
    public static final String FIELD_NAME = "name";

    public static final String TYPE_MANUAL = "M";
    public static final String TYPE_SMART = "S";

    @PrimaryKey
    private long groupId;
    private String name;
    private String type;
    private Integer count;
    @Index
    private long sportId;
    private RealmList<RealmLong> contactIds = new RealmList<>();

    public long getGroupId() {
        return groupId;
    }

    public void setGroupId(final long groupId) {
        this.groupId = groupId;
    }

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(final String type) {
        this.type = type;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(final Integer count) {
        this.count = count;
    }

    public long getSportId() {
        return sportId;
    }

    public void setSportId(final long sportId) {
        this.sportId = sportId;
    }

    public RealmList<RealmLong> getContactIds() {
        return contactIds;
    }

    public void setContactIds(final RealmList<RealmLong> contactIds) {
        this.contactIds = contactIds;
    }

    @Override
    public String toString() {
        return "Group{" +
                "groupId=" + groupId +
                ", name='" + name + '\'' +
                ", type='" + type + '\'' +
                ", count=" + count +
                ", sportId=" + sportId +
                ", contactIds=" + contactIds +
                '}';
    }
}

public class RealmLong extends RealmObject {
    private long value;

    public RealmLong() {
    }

    public RealmLong(final long value) {
        this.value = value;
    }

    public long getValue() {
        return value;
    }

    public void setValue(long value) {
        this.value = value;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        RealmLong realmLong = (RealmLong) o;

        return getValue() == realmLong.getValue();

    }

    @Override
    public int hashCode() {
        return (int) (getValue() ^ (getValue() >>> 32));
    }
}

Version of Realm and tooling

Realm version(s): 4.3.4

Realm sync feature enabled: no

Android Studio version: 3.0.1

Which Android version and device: on a few different devices, currently troubleshooting on API 26 emulator

@bmadaras
Copy link
Author

bmadaras commented Mar 6, 2018

Went through and incrementally updated Realm and it looks like everything works up until version 4.1.1

@Zhuinden
Copy link
Contributor

Zhuinden commented Mar 7, 2018

Does this still happen if you remove the change listener in onDestroy/onDestroyView?

@bmadaras
Copy link
Author

bmadaras commented Mar 7, 2018

Yes the removal of change listeners is in the onDestroy callback and it is still happening.

I was moving around the change listener code and oddly enough what I have found is that if I add the change listener in the onCreate it will crash but if it is added in the onStart method it will not.

This does not make much sense to me.

@cmelchior
Copy link
Contributor

cmelchior commented Mar 8, 2018

I doubt it is related to your model class. Can you try to increase the log level and report the result: RealmLog.setLevel(LogLevel.VERBOSE) ?

@cmelchior
Copy link
Contributor

One observation though: Realm realm = SportRealmConfiguration.getSportRealmInstance(); What does this do? Also, you do not seem to close the Realm instance again, which means your background thread is leaking Realm versions.

@bmadaras
Copy link
Author

bmadaras commented Mar 8, 2018

Sorry for the incomplete code, I was trying not to make my code example so unwieldy.
Here is the code for acquiring the realm.

public class SportRealmConfiguration {
private static final String realmName = "sport.realm";
    public static Realm getSportRealmInstance() {
        return Realm.getInstance(getInstance());
    }
    public static synchronized RealmConfiguration getInstance() {

        if (config == null) {
            config = new RealmConfiguration.Builder()
                    .name(realmName).modules(new MainModule())
                    .schemaVersion(8)
                    .migration(new BaseMigration()).build();
        }
        return config;
    }
}

And as for the leaking for realm versions, I left out the important part when trimming out the other service error handling logic. Every instance that I am acquiring a reference to a realm on a none UI thread I am wrapping in a try finally block. for the UI thread this is handled via the lifecycle destroy methods.

Realm realm = null;
                try {
                    realm = SportRealmConfiguration.getSportRealmInstance();
                } finally {
                    if (realm != null) {
                        realm.close();
                    }
                }

Attached debugging logs.
Crash.log

@bmadaras
Copy link
Author

Does the previous attached log file have the needed information?

@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.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants