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 when updating Realm after 30+ minutes array_basic_tpl.hpp:123: [realm-core-6.0.9] Assertion failed: ndx < m_size [5, 0] #6656

Closed
cferg-entale opened this issue Jul 17, 2020 · 6 comments

Comments

@cferg-entale
Copy link

cferg-entale commented Jul 17, 2020

Goals

Prevent my application from crashing after continuous use

Actual Results

After updating an object in Realm every 2 seconds my application eventually crashes with the stacktrace below. My application is an audio player and playback progress is stored in Realm. While audio is playing the progress is updated every 2 seconds.

/Users/realm/workspace/realm_realm-core_release_6.0.9/src/realm/array_basic_tpl.hpp:123: [realm-core-6.0.9] Assertion failed: ndx < m_size [5, 0]
0   Realm                               0x0000000109cf8474 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Realm                               0x0000000109cf8718 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
2   Realm                               0x000000010976db80 _ZN5realm4util9terminateIJmmEEEvPKcS3_lDpT_ + 144
3   Realm                               0x0000000109c80e98 _ZN5realm3Obj3setIfEERS0_NS_6ColKeyET_b + 1052
4   Realm                               0x000000010986a584 _ZN12_GLOBAL__N_18setValueIfEEvP13RLMObjectBaseN5realm6ColKeyET_ + 84
5   Realm                               0x000000010986a524 _ZZZN12_GLOBAL__N_110makeSetterIffEEP11objc_objectP11RLMPropertyEUb0_ENKUlvE_clEv + 120
6   Realm                               0x000000010986a4a0 ___ZN12_GLOBAL__N_110makeSetterIffEEP11objc_objectP11RLMProperty_block_invoke_2 + 240
7   Entale                              0x0000000104d02314 $s6Entale15PlaybackHistoryC18updateProgressData33_64BC4DC07B202437F4FE0DBD10E3DC61LL9contentId8position8durationyAA07ContentP0O_S2dSgtFy10RealmSwift0T0VXEfU0_ + 204
8   Entale                              0x0000000104cea6cc $s10RealmSwift0A0V6EntaleE5writeyyyACKXEKFyyXEfU_ + 96
9   Entale                              0x0000000104ce9ddc $s10RealmSwift0A0V6EntaleE9safeWrite33_9A8FC24798E030663DEFD3E32840878DLLyyyyKXEKF + 148
10  Entale                              0x0000000104cea570 $s10RealmSwift0A0V6EntaleE5writeyyyACKXEKF + 140
11  Entale                              0x0000000104f568c8 $s6Entale19DefaultRealmServiceC5writeyyy0C5Swift0C0VKXEKF + 128
12  Entale                              0x0000000104f57ec8 $s6Entale19DefaultRealmServiceCAA0cD0A2aDP5writeyyy0C5Swift0C0VKXEKFTW + 24
13  Entale                              0x0000000104d01e94 $s6Entale15PlaybackHistoryC18updateProgressData33_64BC4DC07B202437F4FE0DBD10E3DC61LL9contentId8position8durationyAA07ContentP0O_S2dSgtF + 1136
14  Entale                              0x0000000104d019f8 $s6Entale15PlaybackHistoryC15progressUpdated33_64BC4DC07B202437F4FE0DBD10E3DC61LLyyAA16DataNotificationVyAA0B6UpdateVGFyycfU_ + 432
15  Entale                              0x0000000104cfdce0 $sIeg_IeyB_TR + 56
16  libdispatch.dylib                   0x000000010b2097fc _dispatch_call_block_and_release + 24
17  libdispatch.dylib                   0x000000010b20abd8 _dispatch_client_callout + 16
18  libdispatch.dylib                   0x000000010b218c34 _dispatch_main_queue_callback_4CF + 1316
19  CoreFoundation                      0x000000019994c5e4 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 693732
20  CoreFoundation                      0x00000001999475d8 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 673240
21  CoreFoundation                      0x0000000199946adc CFRunLoopRunSpecific + 464
22  GraphicsServices                    0x00000001a38e7328 GSEventRunModal + 104
23  UIKitCore                           0x000000019da5463c UIApplicationMain + 1936
24  Entale                              0x0000000104cd72fc main + 128
25  libdyld.dylib                       0x00000001997d0360 7B531A15-3E73-3185-90E2-B88D9476DA5E + 4960!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to help@realm.io.2020-07-16 17:57:55.755841+0100 Entale[809:304792] /Users/realm/workspace/realm_realm-core_release_6.0.9/src/realm/array_basic_tpl.hpp:123: [realm-core-6.0.9] Assertion failed: ndx < m_size [5, 0]
0   Realm                               0x0000000109cf8474 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Realm                               0x0000000109cf8718 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
2   Realm                               0x000000010976db80 _ZN5realm4util9terminateIJmmEEEvPKcS3_lDpT_ + 144
3   Realm                               0x0000000109c80e98 _ZN5realm3Obj3setIfEERS0_NS_6ColKeyET_b + 1052
4   Realm                               0x000000010986a584 _ZN12_GLOBAL__N_18setValueIfEEvP13RLMObjectBaseN5realm6ColKeyET_ + 84
5   Realm                               0x000000010986a524 _ZZZN12_GLOBAL__N_110makeSetterIffEEP11objc_objectP11RLMPropertyEUb0_ENKUlvE_clEv + 120
6   Realm                               0x000000010986a4a0 ___ZN12_GLOBAL__N_110makeSetterIffEEP11objc_objectP11RLMProperty_block_invoke_2 + 240
7   Entale                              0x0000000104d02314 $s6Entale15PlaybackHistoryC18updateProgressData33_64BC4DC07B202437F4FE0DBD10E3DC61LL9contentId8position8durationyAA07ContentP0O_S2dSgtFy10RealmSwift0T0VXEfU0_ + 204
8   Entale                              0x0000000104cea6cc $s10RealmSwift0A0V6EntaleE5writeyyyACKXEKFyyXEfU_ + 96
9   Entale                              0x0000000104ce9ddc $s10RealmSwift0A0V6EntaleE9safeWrite33_9A8FC24798E030663DEFD3E32840878DLLyyyyKXEKF + 148
10  Entale                              0x0000000104cea570 $s10RealmSwift0A0V6EntaleE5writeyyyACKXEKF + 140
11  Entale                              0x0000000104f568c8 $s6Entale19DefaultRealmServiceC5writeyyy0C5Swift0C0VKXEKF + 128
12  Entale                              0x0000000104f57ec8 $s6Entale19DefaultRealmServiceCAA0cD0A2aDP5writeyyy0C5Swift0C0VKXEKFTW + 24
13  Entale                              0x0000000104d01e94 $s6Entale15PlaybackHistoryC18updateProgressData33_64BC4DC07B202437F4FE0DBD10E3DC61LL9contentId8position8durationyAA07ContentP0O_S2dSgtF + 1136
14  Entale                              0x0000000104d019f8 $s6Entale15PlaybackHistoryC15progressUpdated33_64BC4DC07B202437F4FE0DBD10E3DC61LLyyAA16DataNotificationVyAA0B6UpdateVGFyycfU_ + 432
15  Entale                              0x0000000104cfdce0 $sIeg_IeyB_TR + 56
16  libdispatch.dylib                   0x000000010b2097fc _dispatch_call_block_and_release + 24
17  libdispatch.dylib                   0x000000010b20abd8 _dispatch_client_callout + 16
18  libdispatch.dylib                   0x000000010b218c34 _dispatch_main_queue_callback_4CF + 1316
19  CoreFoundation                      0x000000019994c5e4 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 693732
20  CoreFoundation                      0x00000001999475d8 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 673240
21  CoreFoundation                      0x0000000199946adc CFRunLoopRunSpecific + 464
22  GraphicsServices                    0x00000001a38e7328 GSEventRunModal + 104
23  UIKitCore                           0x000000019da5463c UIApplicationMain + 1936
24  Entale                              0x0000000104cd72fc main + 128
25  libdyld.dylib                       0x00000001997d0360 7B531A15-3E73-3185-90E2-B88D9476DA5E + 4960!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to help@realm.io.
(lldb) 

Steps to Reproduce

Update an existing Ream object periodically (every 2 seconds) for 30 minutes or more (this is anecdotal based on usage)

Code Sample

The below code crashes

try database.write { _ in
    data.progress = position.formatted // this crashes
    data.lastPlayed = now.isoFormatted
    if let duration = duration {
        data.duration = duration.formatted
    }
}

database.write is declared as:

func write(_ block: (Realm) throws -> Void) throws {
    let realm = try getRealm()
    try realm.write(block)
}

where realm.write is an Extension on Realm:

extension Realm {
    func write(_ block: (Realm) throws -> Void) throws {
        var writeError: Swift.Error?
        try safeWrite {
            do {
                try block(self)
            } catch let error {
                writeError = error
            }
        }
        if let error = writeError {
            throw error
        }
    }

    func safeWrite(_ block: (() throws -> Void)) throws {
        if isInWriteTransaction {
            try block()
        } else {
            try write(block)
        }
    }
}

Version of Realm and Tooling

Realm framework version: RealmSwift version 5.3.0
Xcode version: 11.5 (11E608c)
iOS/OSX version: Crash experienced on multiple iOS devices including iOS 13.5.1
Dependency manager + version: CocoaPods 1.9.3

@bmunkholm bmunkholm changed the title Crash when updating Realm after 30+ minutes Assertion failed: ndx < m_size [5, 0] Crash when updating Realm after 30+ minutes array_basic_tpl.hpp:123: [realm-core-6.0.9] Assertion failed: ndx < m_size [5, 0] Jul 17, 2020
@bmunkholm
Copy link
Contributor

Thanks for reporting this!
The "Steps to reproduce" is for how WE can reproduce :-)
Any way for us to do that?

@cferg-entale
Copy link
Author

Gotcha. I have updated the "Steps to reproduce" section. I am in the process of investigating whether the frequency of the writes affects the frequency of the errors

@bmunkholm
Copy link
Contributor

@cferg-entale Just got back from vacation. The "Steps to reproduce" isn't enough to lead us to the crash. Any chance you can provide a full but minimal repro case project?

@cferg-entale
Copy link
Author

@bmunkholm, apologies for the late reply.

This crash is actually caused by realm already being in a write transaction. The solution was to avoid calling write() if realm was in a write transaction.

I don't know whether calling write() on a Realm instance should be avoided if the instance is already in a write transaction. The odd thing is that all writes were being performed on the same (main) thread.

@jedelbo
Copy link

jedelbo commented Sep 16, 2020

This could also be a variation of realm/realm-java#7057

@bmunkholm
Copy link
Contributor

@cferg-entale Yeah you shouldn't be doing write transactions within write transactions. But also you shouldn't be able to provoke a crash like this. Since you haven't seen this again and since above hints at this potentially being fixed, I'll close this for now. Please do create a new issue should you see this again.
Thanks!

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