realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.32k stars 2.15k forks source link

Assertion failed: previous <= m_schema_transaction_version_max #4830

Closed fishfisher closed 7 years ago

fishfisher commented 7 years ago

Goals

Everytime I launch my app on a new simulator I see this crash. When I launch the simulator the second time the app runs fine. I want to identify reason for crash.

Expected Results

This crash started after updating to RealmSwift 2.5.1. What seems to be the reason for this crash?

The crash does not happen on a simulator where the app is already installed and the crash does not happen if I select 'Reset Content and Settings'. Only on initial launch.. EDIT: It does seem to crash after 'Reset Content and Settings' on the simulator.

Actual Results

Crashes on initial launch of a newly selected iOS simulator with the following stack trace:

/Pods/Realm/Realm/ObjectStore/src/impl/realm_coordinator.cpp:289: [realm-core-2.5.1] Assertion failed: previous <= m_schema_transaction_version_max
0   Realm                               0x0000000105df6af8 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 40
1   Realm                               0x0000000105df6df5 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 517
2   Realm                               0x0000000105abc453 _ZN5realm5_impl16RealmCoordinator20advance_schema_cacheEyy + 371
3   Realm                               0x0000000105cdd98d _ZN5realm5Realm16cache_new_schemaEv + 349
4   Realm                               0x0000000105cde3f3 _ZN5realm5Realm17begin_transactionEv + 787
5   Realm                               0x0000000105c82d0e -[RLMRealm beginWriteTransaction] + 46
6   RealmSwift                          0x00000001064c418d _TFC10RealmSwift5Realm10beginWritefT_T_ + 45
7   RealmSwift                          0x00000001064c4070 _TFC10RealmSwift5Realm5writefzFzT_T_T_ + 48
8   appName                            0x0000000104c19d33 _TZFe8AppNameRxC10RealmSwift6ObjectxS_17ClassAsPrimaryKeyxS_16GetNewOrExistingrS3_16getNewOrExistingfzSbT6objectx10createdNewSb_ + 1123
9   appName                            0x0000000104cf9fb1 _TFC8appName11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryVSC29UIApplicationLaunchOptionsKeyP____Sb + 14193
10  appName                            0x0000000104cfcc44 _TToFC8appName11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryVSC29UIApplicationLaunchOptionsKeyP____Sb + 180
11  UIKit                               0x0000000106ee0957 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 299
12  UIKit                               0x0000000106ee223c -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4119
13  UIKit                               0x0000000106ee8584 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1709
14  UIKit                               0x0000000106ee5793 -[UIApplication workspaceDidEndTransaction:] + 182
15  FrontBoardServices                  0x000000010f4065f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
16  FrontBoardServices                  0x000000010f40646d -[FBSSerialQueue _performNext] + 186
17  FrontBoardServices                  0x000000010f4067f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
18  CoreFoundation                      0x000000010b52ac01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19  CoreFoundation                      0x000000010b5100cf __CFRunLoopDoSources0 + 527
20  CoreFoundation                      0x000000010b50f5ff __CFRunLoopRun + 911
21  CoreFoundation                      0x000000010b50f016 CFRunLoopRunSpecific + 406
22  UIKit                               0x0000000106ee402f -[UIApplication _run] + 468
23  UIKit                               0x0000000106eea0d4 UIApplicationMain + 159
24  appName                            0x0000000104d0da97 main + 55
25  libdyld.dylib                       0x000000010c86465d start + 1
26  ???                                 0x0000000000000001 0x0 + 1

Steps to Reproduce

I do not know how to reproduce unfortunately.

Version of Realm and Tooling

pigeon-archive commented 7 years ago

Hi @fishfisher. Thanks for filing this issue. We'll look into this and follow-up here with our findings (if we have any). Cheers!

tgoyne commented 7 years ago

I didn't have any luck with auditing the code in the hopes of figuring out what could cause this, and there's not much else I can do without more information.

fishfisher commented 7 years ago

Thanks for getting back to me. Let me know I you need anything from me. What does 'previous <= m_schema_transaction_version_max' mean? I tried downgrading to Realm 2.5.0, but the crash still happens. The weird thing it is still referencing 2.5.1 with this assertion: /Pods/Realm/Realm/ObjectStore/src/impl/realm_coordinator.cpp:289: [realm-core-2.5.1] Assertion failed: previous <= m_schema_transaction_version_max

jpsim commented 7 years ago

Sorry for the delay, I'm afraid there's nothing we can do without being able to reproduce this ourselves, so sharing a sample project that triggers this would be the best way to help us investigate.

The reason the assertion failure is still reporting 2.5.1 is that it happens to be the version of Realm's core that both Realm Swift 2.5.0 and 2.5.1 are using: https://github.com/realm/realm-core/releases/v2.5.1

jpsim commented 7 years ago

This was reported by another user on Helpscout: https://secure.helpscout.net/conversation/343721163/9413/?folderId=366245

Assertion failure stack trace with identifiable information redacted:

Realm/ObjectStore/src/impl/realm_coordinator.cpp:289: [realm-core-2.5.1] Assertion failed: previous <= m_schema_transaction_version_max
0 Realm 0x0000000101016198 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 44
1 Realm 0x00000001010163e8 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 388
2 Realm 0x0000000100d6d9d0 _ZN5realm5_impl16RealmCoordinator20advance_schema_cacheEyy + 272
3 Realm 0x0000000100f26c98 _ZN5realm5Realm16cache_new_schemaEv + 256
4 Realm 0x0000000100f276ac _ZN5realm5Realm17begin_transactionEv + 624
5 Realm 0x0000000100edc658 -[RLMRealm beginWriteTransaction] + 48
6 RealmSwift 0x0000000101661844 _TFC10RealmSwift5Realm10beginWritefT_T_ + 56
7 [REDACTED] 0x00000001017ead6c [REDACTED]
8 [REDACTED] 0x00000001017f2c80 [REDACTED]
9 [REDACTED] 0x00000001017d74d4 [REDACTED]
10 [REDACTED] 0x00000001017d0630 [REDACTED]
11 [REDACTED] 0x00000001017d6a9c [REDACTED]
12 [REDACTED] 0x00000001017c8780 [REDACTED]
13 [REDACTED] 0x0000000101815be0 [REDACTED]
14 [REDACTED] 0x00000001017c854c [REDACTED]
15 [REDACTED] 0x0000000101807154 [REDACTED]
16 Alamofire 0x00000001003d9238 _TTRXFo_oGV9Alamofire12DataResponseSS___XFo_iGS0_SS___ + 172
17 Alamofire 0x00000001003d5a04 _TFFFC9Alamofire11DataRequest8responseuRxS_30DataResponseSerializerProtocolrFT5queueGSqCSo13DispatchQueue_18responseSerializerx17completionHandlerFGVS_12DataResponsewx16SerializedObject_T__DS0_U_FT_T_U_FT_T_ + 708
18 Alamofire 0x000000010039d35c _TTRXFo___XFdCb___ + 44
19 libdispatch.dylib 0x000000010250d25c _dispatch_call_block_and_release + 24
20 libdispatch.dylib 0x000000010250d21c _dispatch_client_callout + 16
21 libdispatch.dylib 0x0000000102512284 _dispatch_main_queue_callback_4CF + 1200
22 CoreFoundation 0x0000000185f3ff2c <redacted> + 12
23 CoreFoundation 0x0000000185f3db18 <redacted> + 1660
24 CoreFoundation 0x0000000185e6c048 CFRunLoopRunSpecific + 444
25 GraphicsServices 0x00000001878f2198 GSEventRunModal + 180
26 UIKit 0x000000018be582fc <redacted> + 684
27 UIKit 0x000000018be53034 UIApplicationMain + 208
28 [REDACTED] 0x00000001000241a0 main + 76
29 libdyld.dylib 0x0000000184e505b8 <redacted> + 4
fishfisher commented 7 years ago

Thanks for getting back to me. Luckily I have not seen a single instance of this crash for the released version. I'll get in touch if I find anything useful related to the issue!

jpsim commented 7 years ago

Thanks for reporting back. We'll reopen if someone sees this again with Realm ObjC or Swift 2.6 or later.

Vanilil commented 7 years ago

Hello, i've had the same issues when I launch my app with the last version of Realm ObjC on a new simulator for the first time.

After some transaction, I have 'previous' = 5 et 'm_schema_transaction_version_max' = 4 when it comes to the lines:

REALM_ASSERT(previous <= m_schema_transaction_version_max);

this is the stack trace, i have :

 /Pods/Realm/Realm/ObjectStore/src/impl/realm_coordinator.cpp:289: [realm-core-2.6.2] Assertion failed: previous <= m_schema_transaction_version_max
0   []               0x00a2db90 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 48
1   []               0x00a2dfbc _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 492
2   []               0x005b25e1 _ZN5realm5_impl16RealmCoordinator20advance_schema_cacheEyy + 401
3   []               0x007e9115 _ZN5realm5Realm16cache_new_schemaEv + 325
4   []               0x007e93b0 _ZN5realm5Realm18commit_transactionEv + 384
5   []               0x0077aaeb -[RLMRealm commitWriteTransaction:] + 59
6   []               0x0077b109 -[RLMRealm transactionWithBlock:error:] + 185
7   []               0x00344553 +[] + 307
8   []               0x00090ce2 +[] + 98
9   []               0x00363bfb -[] + 139
10  []               0x003636b7 __35-[]_block_invoke_2 + 311
11  []               0x0020ea70 __42+[]_block_invoke + 304
12  []               0x003a662b __116-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:]_block_invoke.97 + 219
13  []               0x003ccb59 __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.150 + 217
14  libdispatch.dylib                   0x0705e377 _dispatch_call_block_and_release + 15
15  libdispatch.dylib                   0x070819cd _dispatch_client_callout + 14
16  libdispatch.dylib                   0x07066f90 _dispatch_main_queue_callback_4CF + 910
17  CoreFoundation                      0x067975fe __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
18  CoreFoundation                      0x067552f4 __CFRunLoopRun + 2356
19  CoreFoundation                      0x06754706 CFRunLoopRunSpecific + 470
20  CoreFoundation                      0x0675451b CFRunLoopRunInMode + 123
21  GraphicsServices                    0x094c6664 GSEventRunModal + 192
22  GraphicsServices                    0x094c64a1 GSEventRun + 104
23  UIKit                               0x03b2d1eb UIApplicationMain + 160
24  []               0x003a082c main + 140
25  libdyld.dylib                       0x070aba21 start + 1
26  ???                                 0x00000001 0x0 + 1
jpsim commented 7 years ago

@Vanilil thanks for sharing! I think yours is the first report of this crash since this issue was closed. From what you're saying, it seems like you have a reproduction case. We have yet to be able to reproduce this ourselves, so we'd greatly appreciate if you could send a project that reliably triggers this crash to help@realm.io, linking to this issue so we know what it's in reference to. Thanks for your assistance!

anujbhambhani commented 6 years ago

I am also seeing this issue sometimes in my project but I don't have definitive repro steps.

RetVal commented 6 years ago

I am also seeing this issue sometimes in my project, any updates?

ruipfcosta commented 5 years ago

I'm seeing this crash on versions 3.18.0 and 3.19.0 after migrating to Xcode 11 from version 3.16.0. I can replicate this when running unit tests from a clean simulator (which becomes an problem on CI). As a solution I ended up upgrading from version 3.16.0 to 3.17.3.

ctscoville commented 5 years ago

I'm seeing this crash as well on 3.18.0 and 3.19.1. I guess for the time being I can downgrade to v3.17.3.

georgejlee commented 5 years ago

I also see this on 3.21.0 and Xcode 11.

taarond commented 5 years ago

also seeing this in 3.21.0 and xcode 11.2. sent the debug report to help @ realm

chris-engel-ios commented 4 years ago

Edit, this solution failed QA / UAT

This seems to have resolved the issue for 13.2.2 simulator, but when distributing via Fabric/Beta this failed testing.

Solution (failed QA)

Solved this for our use case by checking if the realm database existed, before performing the schema version comparison required for migrations.

The initial logic to solve this was:

 if FileManager.default.fileExists(atPath: YOUR_REALM_FILEPATH) {
     // Database exists, compare schema version and migrate if needed. 
 } else {
     // Realm does not exist, set DB to the current schema, no migrations
 }

This ended up being a ternary placed before the existing Realm.Configuration containing migrations.

    let filePath = YOUR_REALM_FILEPATH ?? "SOME_DEFAULT"
    let TERNARY_VALUE = !FileManager.default.fileExists(atPath: filePath) ?
        Realm.Configuration(schemaVersion: YOUR_SCHEMA_VERSION) :
        Realm.Configuration(schemaVersion: YOUR_SCHEMA_VERSION, migrationBlock:
        [Existing migration block]

This solved our iOS crash during initial application install, triggered by schema version comparison.

Version of Realm and Tooling:

Realm framework version: 3.18.0 Xcode version: 11.2.1 iOS/OSX version: 13.2.2 Dependency manager: CocoaPods

DPigramIBM commented 4 years ago

@chris-engel-ios Are you accessing the file path by Realm.Configuration.defaultConfiguration.fileURL?

chris-engel-ios commented 4 years ago

@DPigramIBM,

We are using: Realm.Configuration.defaultConfiguration.fileURL?.absoluteString ?? "NONE" to define the filePath of the RealmDB.

tpoche commented 4 years ago

I started seeing this same error yesterday in my unit tests running the latest version of Realm (v4.3.2). My unit tests configure an in-memory Realm as recommended in the docs: // setup default Realm configuration to use in-memory database Realm.Configuration.defaultConfiguration.inMemoryIdentifier = self.name

I've attached the stack trace for reference. Any help or guidance is appreciated! RealmCrashStackTrace.txt

bmunkholm commented 4 years ago

@tpoche (and others), please create a new issue (with reference to this) instead of commenting on closed issues (it's usually not seen). A new issue has a template to ensure we get the most relevant facts. @tpoche If you are seeing this in a unit test consistently, can you please reduce this down to code you can share? Thanks!

EricWiener commented 4 years ago

In case it helps anyone, I also got this issue. I was running a migration in RealmJS, but also accessing items with RealmSwift at the same time to back them up to iCloud. I needed to wait until the migration completed before starting the Realm in Swift.

bmunkholm commented 4 years ago

@EricWiener New issue please.

EricWiener commented 4 years ago

@bmunkholm I can start a new issue if you like, but this one was definitely my fault. I was just posting to let other’s know what to avoid.