realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.69k stars 564 forks source link

Corrupt Database on iOS 17 #6477

Open ax88 opened 5 months ago

ax88 commented 5 months ago

How frequently does the bug occur?

Sometimes

Description

Our app what working fine with realm 3.6.5 since 5 years ago. Recent update of iOS 17 on certain type of iPad (iPad 6, 7 and iPad Pro 12.9 2nd gen and iPad pro 10.5inch), which runs on Apple A10 and A10X chips, makes the app crash after few days or weeks of use. When the crash occurs, I have able to reproduce It. There is basically two case:

1 / We cannot start the app: Decryption failed: 'unable to decrypt after 0 seconds (retry_count=0, from=i != bytes_read, size=4096)' or sometime: Assertion failed: is_not(e, Writable)

2/ We can start the app: Decryption failed: 'unable to decrypt after 0 seconds (retry_count=0, from=i != bytes_read, size=16384)' or Assertion failed: is_not(e, Writable) or The Realm is already in a write transaction

I even try to to open the DB with Realm Studio and I've got this error: Decryption failed: 'unable to decrypt after 0 seconds (retry_count=0, from=i != bytes_read, size=4096)'

Stacktrace & log output

realm-core/src/realm/util/encrypted_file_mapping.cpp:591: [realm-core-13.26.0] Assertion failed: is_not(e, Writable)
0 lanote 0x0000000104b865f4 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1 lanote 0x0000000104b86570 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 404
2 lanote 0x0000000104b863dc _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0
3 lanote 0x0000000104b69e08 _ZN5realm4util20EncryptedFileMappingD2Ev + 308
4 lanote 0x0000000104b73a00 _ZN5realm4util12_GLOBAL__N_114remove_mappingEPvm + 384
5 lanote 0x0000000104b713d8 _ZN5realm4util4File7MapBase5unmapEv + 56
6 lanote 0x0000000104a43520 _ZNSt3__16vectorINS_10unique_ptrIN5realm14WriteWindowMgr9MapWindowENS_14default_deleteIS4_EEEENS_9allocatorIS7_EEED2B6v15006Ev + 56
7 lanote 0x0000000104a3e7cc _ZN5realm11GroupWriterD2Ev + 108
8 lanote 0x0000000104a1c678 _ZN5realm2DB16low_level_commitEyRNS_11TransactionEb + 1384
9 lanote 0x0000000104a1c070 _ZN5realm2DB9do_commitERNS_11TransactionEb + 252
10 lanote 0x0000000104b525c8 _ZN5realm11Transaction27commit_and_continue_as_readEb + 72
11 lanote 0x00000001047dbcec _ZN5realm5_impl16RealmCoordinator12commit_writeERNS_5RealmEb + 100
12 lanote 0x0000000104839244 _ZN5realm5Realm18commit_transactionEv + 140
13 lanote 0x00000001047433c8 _ZN5realm2js3JSI12_GLOBAL__N_124Realm_commit_transactionERN8facebook3jsi7RuntimeERKNS4_5ValueEPS8_m + 72
14 lanote 0x000000010584d1a4 _ZNKSt3__110__function12__value_funcIFN8facebook3jsi5ValueERNS3_7RuntimeERKS4_PS7_mEEclB7v160006ES6_S8_OS9_Om + 112
15 lanote 0x000000010584cbc0 _ZNKSt3__18functionIFN8facebook3jsi5ValueERNS2_7RuntimeERKS3_PS6_mEEclES5_S7_S8_m + 72
16 lanote 0x000000010584c3bc ZZN8facebook3jsc10JSCRuntime30createFunctionFromHostFunctionERKNS_3jsi10PropNameIDEjNSt3__18functionIFNS2_5ValueERNS2_7RuntimeERKS8_PSB_mEEEEN20HostFunctionMetadata4callEPK15OpaqueJSContextP13OpaqueJSValueSL_mPKPKSK_PSN + 720
17 JavaScriptCore 0x00000001bb5fa3ac 4958E78D-63AF-3558-9959-F9F3C575FF22 + 5170092
18 JavaScriptCore 0x00000001bbe6bc08 4958E78D-63AF-3558-9959-F9F3C575FF22 + 14023688
19 JavaScriptCore 0x00000001bbebf630 4958E78D-63AF-3558-9959-F9F3C575FF22 + 14366256
20 JavaScriptCore 0x00000001bb4b0ed4 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3821268
21 JavaScriptCore 0x00000001bb4ae698 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3810968
22 JavaScriptCore 0x00000001bb4aecfc 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3812604
23 JavaScriptCore 0x00000001bb4adc2c 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3808300
24 JavaScriptCore 0x00000001bb4aecfc 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3812604
25 JavaScriptCore 0x00000001bb4aecfc 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3812604
26 JavaScriptCore 0x00000001bb4af158 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3813720
27 JavaScriptCore 0x00000001bb4aecb0 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3812528
28 JavaScriptCore 0x00000001bb4adc2c 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3808300
29 JavaScriptCore 0x00000001bb4aecb0 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3812528
30 JavaScriptCore 0x00000001bb489008 4958E78D-63AF-3558-9959-F9F3C575FF22 + 3657736
31 JavaScriptCore 0x00000001bbd7fbe4 4958E78D-63AF-3558-9959-F9F3C575FF22 + 13056996
32 JavaScriptCore 0x00000001bb60aed4 JSObjectCallAsFunction + 516
33 lanote 0x0000000105847d28 _ZN8facebook3jsc10JSCRuntime4callERKNS_3jsi8FunctionERKNS2_5ValueEPS7_m + 268
34 lanote 0x00000001061adde8 _ZNK8facebook3jsi8Function4callERNS0_7RuntimeEPKNS0_5ValueEm + 100
35 lanote 0x00000001061add78 _ZNK8facebook3jsi8Function4callERNS0_7RuntimeESt16initializer_listINS0_5ValueEE + 112
36 lanote 0x00000001061c2b18 ZNK8facebook3jsi8Function4callIJRKdNS0_5ValueEEEES5_RNS0_7RuntimeEDpOT + 184
37 lanote 0x00000001061c2894 _ZN8facebook5react11JSIExecutor14invokeCallbackEdRKN5folly7dynamicE + 188
38 lanote 0x0000000105a97a34 _ZZN8facebook5react16NativeToJsBridge14invokeCallbackEdON5folly7dynamicEENK3$_3clEPNS0_10JSExecutorE + 272
39 lanote 0x0000000105a97918 _ZNSt3__18__invokeB7v160006IRZN8facebook5react16NativeToJsBridge14invokeCallbackEdON5folly7dynamicEE3$3JPNS2_10JSExecutorEEEEDTclclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT0_EEEEOSB_DpOSC + 36
40 lanote 0x0000000105a978c4 _ZNSt3__128__invoke_void_return_wrapperIvLb1EE6__callIJRZN8facebook5react16NativeToJsBridge14invokeCallbackEdON5folly7dynamicEE3$3PNS4_10JSExecutorEEEEvDpOT + 32
41 lanote 0x0000000105a97898 _ZNSt3__110__function12__alloc_funcIZN8facebook5react16NativeToJsBridge14invokeCallbackEdON5folly7dynamicEE3$3NS_9allocatorIS8_EEFvPNS3_10JSExecutorEEEclB7v160006EOSC + 36
42 lanote 0x0000000105a9662c _ZNSt3__110__function6__funcIZN8facebook5react16NativeToJsBridge14invokeCallbackEdON5folly7dynamicEE3$3NS_9allocatorIS8_EEFvPNS3_10JSExecutorEEEclEOSC + 36
43 lanote 0x0000000105aa07d8 ZNKSt3__110__function12__value_funcIFvPN8facebook5react10JSExecutorEEEclB7v160006EOS5 + 76
44 lanote 0x0000000105aa0758 ZNKSt3__18functionIFvPN8facebook5react10JSExecutorEEEclES4 + 36
45 lanote 0x0000000105aa0724 _ZZN8facebook5react16NativeToJsBridge18runOnExecutorQueueENSt3__18functionIFvPNS0_10JSExecutorEEEEENK3$_8clEv + 92
46 lanote 0x0000000105aa06bc _ZNSt3__18__invokeB7v160006IRZN8facebook5react16NativeToJsBridge18runOnExecutorQueueENS_8functionIFvPNS2_10JSExecutorEEEEE3$8JEEEDTclclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT0_EEEEOSB_DpOSC + 24
47 lanote 0x0000000105aa0674 _ZNSt3__128__invoke_void_return_wrapperIvLb1EE6__callIJRZN8facebook5react16NativeToJsBridge18runOnExecutorQueueENS_8functionIFvPNS4_10JSExecutorEEEEE3$8EEEvDpOT + 24
48 lanote 0x0000000105aa0650 _ZNSt3__110__function12__alloc_funcIZN8facebook5react16NativeToJsBridge18runOnExecutorQueueENS_8functionIFvPNS3_10JSExecutorEEEEE3$_8NS_9allocatorISA_EEFvvEEclB7v160006Ev + 28
49 lanote 0x0000000105a9f1e4 _ZNSt3__110__function6__funcIZN8facebook5react16NativeToJsBridge18runOnExecutorQueueENS_8functionIFvPNS3_10JSExecutorEEEEE3$_8NS_9allocatorISA_EEFvvEEclEv + 28
50 lanote 0x00000001058360e4 _ZNKSt3__110__function12__value_funcIFvvEEclB7v160006Ev + 68
51 lanote 0x0000000105836000 _ZNKSt3__18functionIFvvEEclEv + 24
52 lanote 0x00000001057244fc _ZN8facebook5react17tryAndReturnErrorERKNSt3__18functionIFvvEEE + 24
53 lanote 0x0000000105747a54 _ZN8facebook5react16RCTMessageThread7tryFuncERKNSt3__18functionIFvvEEE + 36
54 lanote 0x000000010574c4cc _ZZN8facebook5react16RCTMessageThread10runOnQueueEONSt3__18functionIFvvEEEENK3$_1clEv + 80
55 lanote 0x000000010574c470 _ZNSt3__18__invokeB7v160006IRZN8facebook5react16RCTMessageThread10runOnQueueEONS_8functionIFvvEEEE3$1JEEEDTclclsr3stdE7declvalIT_EEspclsr3stdE7declvalIT0_EEEEOSA_DpOSB + 24
56 lanote 0x000000010574c428 _ZNSt3__128__invoke_void_return_wrapperIvLb1EE6__callIJRZN8facebook5react16RCTMessageThread10runOnQueueEONS_8functionIFvvEEEE3$1EEEvDpOT + 24
57 lanote 0x000000010574c404 _ZNSt3__110__function12__alloc_funcIZN8facebook5react16RCTMessageThread10runOnQueueEONS_8functionIFvvEEEE3$_1NS_9allocatorIS9_EES6_EclB7v160006Ev + 28
58 lanote 0x000000010574b114 _ZNSt3__110__function6__funcIZN8facebook5react16RCTMessageThread10runOnQueueEONS_8functionIFvvEEEE3$_1NS_9allocatorIS9_EES6_EclEv + 28
59 lanote 0x00000001058360e4 _ZNKSt3__110__function12__value_funcIFvvEEclB7v160006Ev + 68
60 lanote 0x0000000105836000 _ZNKSt3__18functionIFvvEEclEv + 24
61 lanote 0x00000001057477bc ___ZN8facebook5react16RCTMessageThread8runAsyncENSt3__18functionIFvvEEE_block_invoke + 48
62 CoreFoundation 0x00000001a6c66364 1B48137D-6256-3164-9EC3-124F0AA34B77 + 217956
63 CoreFoundation 0x00000001a6c64c88 1B48137D-6256-3164-9EC3-124F0AA34B77 + 212104
64 CoreFoundation 0x00000001a6c6326c 1B48137D-6256-3164-9EC3-124F0AA34B77 + 205420
65 CoreFoundation 0x00000001a6c627a4 CFRunLoopRunSpecific + 572
66 lanote 0x00000001056fd5bc +[RCTCxxBridge runRunLoop] + 736
67 Foundation 0x00000001a5d66ed4 E2C17CC6-DCFF-342F-BE9C-00FEED3C07CD + 683732
68 libsystem_pthread.dylib 0x000000020af6b18c _pthread_start + 104
69 libsystem_pthread.dylib 0x000000020af6ab1c thread_start + 8
!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

Can you reproduce the bug?

Always

Reproduction Steps

Yes I the app start we can reproduce if the bug already happened the first time. If not occured yet, I cannot reprocude it.

Version

3.6.5 to 12.6.0

What services are you using?

Local Database only

Are you using encryption?

Yes

Platform OS and version(s)

iOS 17.x.x

Build environment

React native : 0.64.0 to 0.72.0 Realm JS 3.6.5 to 12.6.0

Cocoapods version

1.12.0

kneth commented 5 months ago

@ax88 Thank you for reporting. Do you also see the crash on a freshly installed app?

ax88 commented 5 months ago

Hello, yes it can happened on a freshly installed app. But It can takes some time before it happened, like few days.

Le mar. 13 févr. 2024 à 16:02, Kenneth Geisshirt @.***> a écrit :

@ax88 https://github.com/ax88 Thank you for reporting. Do you also see the crash on a freshly installed app?

— Reply to this email directly, view it on GitHub https://github.com/realm/realm-js/issues/6477#issuecomment-1941710587, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVMNYO6JJFZLCHNRNEGBLLYTN6BRAVCNFSM6AAAAABDDQDDX2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBRG4YTANJYG4 . You are receiving this because you were mentioned.Message ID: @.***>

kneth commented 5 months ago

it can happened on a freshly installed app

It is unlikely the upgrade of Realm JS, which is the root cause.

You mention that it happens when the app has been running for a while. Can it be that you are writing objects to your Realm file when the device is locked? This might require some additional settings.

ax88 commented 5 months ago

I am not writing to Realm when the device is locked. I am sure that this is not the upgrade of Realm JS because I have users that only upgraded iOS to v17 and they have been using the app for 3 to 5 years. Before the bug, I was only using Realm JS 3.6.5 (from 2019 to 2024). After the bug occurred, I tried to upgrade to 5.0.0, 10.0.0 and 12.0.0 but the crash persisted.

Le mer. 14 févr. 2024 à 11:38, Kenneth Geisshirt @.***> a écrit :

it can happened on a freshly installed app

It is unlikely the upgrade of Realm JS, which is the root cause.

You mention that it happens when the app has been running for a while. Can it be that you are writing objects to your Realm file when the device is locked? This might require some additional settings https://www.mongodb.com/docs/realm/sdk/swift/realm-files/configure-and-open-a-realm/#std-label-use-realm-when-the-device-is-locked .

— Reply to this email directly, view it on GitHub https://github.com/realm/realm-js/issues/6477#issuecomment-1943492092, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVMNYP7AQN3FECNM7AFIKTYTSH3NAVCNFSM6AAAAABDDQDDX2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBTGQ4TEMBZGI . You are receiving this because you were mentioned.Message ID: @.***>

kneth commented 4 months ago

It is unclear how the file ended being corrupted but we will not be able to recover the file. An upgrade will not recover it, and looking at your stack trace, the crash happens when you open the (corrupted) file.