realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

Corrupted tables / database file

Open cristianoccazinsp opened this issue 2 years ago • 22 comments

Description

First time seeing such an error. We've just got a crash report from a user that got the realm database in a state that it cannot start by any means, possibly a corrupted file?

In short await Realm.open always fails with an exception and it cannot be recovered from. See below for more info.

Stacktrace & log output

Exception in HostFunction: No such table exists

Exception backtrace:
0   zinspector3                         0x0000000100d9a03c _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 4825812
1   zinspector3                         0x0000000100d9a1c8 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 4826208
2   zinspector3                         0x0000000100bc0a80 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 2886936
3   zinspector3                         0x0000000100beea50 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 3075304
4   zinspector3                         0x0000000100bee6f8 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 3074448
5   zinspector3                         0x0000000100b926ac _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 2697540
6   zinspector3                         0x0000000100b91b5c _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 2694644
7   zinspector3                         0x0000000100b91824 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 2693820
8   zinspector3                         0x0000000100bef6d0 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 3078504
9   zinspector3                         0x0000000100af73b0 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 2061896
10  zinspector3                         0x0000000100aa57cc _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 1727076
11  zinspector3                         0x0000000100af7604 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 2062492
12  zinspector3                         0x00000001009d90c0 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 889688
13  zinspector3                         0x00000001009d8e08 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 888992
14  JavaScriptCore                      0x000000019f1f67f8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2779128
15  JavaScriptCore                      0x000000019f85cffc F956E7A1-BC64-3D00-BE66-B45BD2222110 + 9490428
16  JavaScriptCore                      0x000000019f853b10 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 9452304
17  JavaScriptCore                      0x000000019f16d390 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2216848
18  JavaScriptCore                      0x000000019f16ced4 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2215636
19  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
20  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
21  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
22  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
23  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
24  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
25  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
26  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
27  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
28  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
29  JavaScriptCore                      0x000000019f16ce2c F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2215468
30  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
31  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
32  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
33  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
34  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
35  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
36  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
37  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
38  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
39  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
40  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
41  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
42  JavaScriptCore                      0x000000019f16ce2c F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2215468
43  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
44  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
45  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
46  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
47  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
48  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
49  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
50  JavaScriptCore                      0x000000019f149c88 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2071688
51  JavaScriptCore                      0x000000019f777da0 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 8551840
52  JavaScriptCore                      0x000000019fa22a20 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 11348512
53  JavaScriptCore                      0x000000019f16e730 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2221872
54  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
55  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
56  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
57  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
58  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
59  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
60  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
61  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
62  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
63  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
64  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
65  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
66  JavaScriptCore                      0x000000019f16d3a4 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2216868
67  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
68  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
69  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
70  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
71  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
72  JavaScriptCore                      0x000000019f16be50 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211408
73  JavaScriptCore                      0x000000019f16bda8 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2211240
74  JavaScriptCore                      0x000000019f149c88 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2071688
75  JavaScriptCore                      0x000000019f777da0 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 8551840
76  JavaScriptCore                      0x000000019fa22a20 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 11348512
77  JavaScriptCore                      0x000000019f16e730 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2221872
78  JavaScriptCore                      0x000000019f149c88 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2071688
79  JavaScriptCore                      0x000000019f777da0 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 8551840
80  JavaScriptCore                      0x000000019fa22a20 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 11348512
81  JavaScriptCore                      0x000000019f149e38 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 2072120
82  JavaScriptCore                      0x000000019f777dd0 F956E7A1-BC64-3D00-BE66-B45BD2222110 + 8551888
83  JavaScriptCore                      0x000000019f97dbdc _ZN3JSC12profiledCallEPNS_14JSGlobalObjectENS_15ProfilingReasonENS_7JSValueERKNS_8CallDataES3_RKNS_7ArgListE + 156
84  JavaScriptCore                      0x000000019f20392c JSObjectCallAsFunction + 648
85  zinspector3                         0x00000001009d72b8 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 882000
86  zinspector3                         0x00000001009e126c _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 922884
87  zinspector3                         0x00000001009d39c0 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 867416
88  zinspector3                         0x000000010091f2fc _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 128404
89  zinspector3                         0x000000010092b630 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 178376
90  zinspector3                         0x000000010092b3e4 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 177788
91  CoreFoundation                      0x0000000196247608 37A3D601-9398-3DC2-9D00-1B162726A4C9 + 632328
92  CoreFoundation                      0x000000019624689c 37A3D601-9398-3DC2-9D00-1B162726A4C9 + 628892
93  CoreFoundation                      0x00000001962413dc 37A3D601-9398-3DC2-9D00-1B162726A4C9 + 607196
94  CoreFoundation                      0x00000001962407d0 CFRunLoopRunSpecific + 572
95  zinspector3                         0x00000001009143c0 _ZN8facebook5react11JSIExecutor21defaultTimeoutInvokerERKNSt3__18functionIFvvEEENS3_IFNS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEEvEEE + 83544
96  Foundation                          0x00000001975fad90 E364C722-33B5-35B0-9A0B-0AFCCB69A18D + 1461648
97  libsystem_pthread.dylib             0x00000001de7fbc74 _pthread_start + 288
98  libsystem_pthread.dylib             0x00000001de800878 thread_start + 8

Can you reproduce a bug?

Not yet

Reproduction Steps

export default async function initDatabase() {
  let res = await Realm.open({
    schema: [
      ...my schemas...
    ],
    schemaVersion: 8,
  });

  return res;
}

Call initDatabase somewhere on app start / root mount, and get the above exception error with the init failure.

Version

10.20.0-beta.4

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS 14.7.1 - iPhone 7 plus

cristianoccazinsp avatar Apr 27 '22 17:04 cristianoccazinsp

Further, the app may have been close to running out of space (~2gb left).

cristianoccazinsp avatar Apr 27 '22 17:04 cristianoccazinsp

@cristianoccazinsp Thanks for reporting this. We will look into the issue. Please let us know is you come upon further information or find a reproduction scenario.

fronck avatar Apr 28 '22 08:04 fronck

In the meantime, what's the best option to handle a scenario like this? What can be done to either the database (discarding corrupted tables)? As it is right now, the app is 100% unable to start until re-installed or if the storage gets wiped by the OS.

cristianoccazinsp avatar Apr 28 '22 14:04 cristianoccazinsp

Has there been any update regarding this? Any discoveries?

cristianoccazinsp avatar May 23 '22 15:05 cristianoccazinsp

@cristianoccazinsp

If the Realm file was created using 10.20.0-beta.3 or earlier, the corruption might be carried forward. If it is the case, I suggest that you delete the Realm file. Your issue has some similarities with https://github.com/realm/realm-js/issues/4525.

kneth avatar May 24 '22 08:05 kneth

The bug report was with 10.20.0-beta.4, so I'm not sure whether or not the user with the issue ever had beta.3.

I haven't seen other uses with this problem so far, but have you guys figured anything else or any work-around in case this ever happens again? Prompting users to re-install an app is really bad. Would an attempt at copy / delete / rename of the realm file recover the corruption or something?

cristianoccazinsp avatar Jul 09 '22 17:07 cristianoccazinsp

@kneth similar user-lock issue but with another crash. We are using 11.0.0-rc.0 and just received this. This user device basically crashes every single time it tries to write an update or insert to the realm database.

This is only a guess, but the schema causing issues is most likely the following. At this point, we are in a situation where the only fix is to have the user re-install and lose all his data.

export const QueueItemSchema = {
  name: 'QueueItem',
  primaryKey: 'id',
  properties: {
    id: 'string', // uuid
    groupId: {type: 'int', indexed: true},
    priority: {type: 'int', indexed: true},
    mobile: {type: 'bool'},
    added: {type: 'int', indexed: true},
    preventsSync: {type: 'bool', indexed: true},
    uploading: 'bool',
    error: 'bool',
    errorInfo: 'string',
    locked: {type: 'bool', default: false},
    lastUpdate: {type: 'int'},
    uploadData: 'string', //json serialized data
    extraUploadData: {type: 'string', optional: true}, // json serialized data
    uri: {type: 'string', optional: true},
  },
};

Further, this started happening after an app update, probably when upgrading realm from a version beta version as well.

And the crash log.

Role:               Foreground
OS Version:         iOS 15.5
Exception Type:     EXC_BAD_ACCESS 
Exception Subtype:  KERN_INVALID_ADDRESS


EXC_BAD_ACCESS: Attempted to dereference garbage pointer 0xe02835060e0.

0  zinspector3             realm::Array::blob_size() const (zinspector3)
1  zinspector3             realm::ArrayBlob::replace(unsigned long, unsigned long, char const*, unsigned long, bool) (zinspector3)
2  zinspector3             realm::ArraySmallBlobs::insert(unsigned long, realm::BinaryData, bool) (zinspector3)
3  zinspector3             void realm::Cluster::do_insert_row<realm::ArrayString>(unsigned long, realm::ColKey, realm::Mixed, bool) (zinspector3)
4  zinspector3             realm::util::FunctionRef<bool (realm::ColKey)>::FunctionRef<realm::Cluster::insert_row(unsigned long, realm::ObjKey, realm::FieldValues const&)::$_1&>(realm::Cluster::insert_row(unsigned long, realm::ObjKey, realm::FieldValues const&)::$_1&)::{lambda(void*, realm::ColKey)#1}::__invoke(void*, realm::ColKey) (zinspector3)
5  zinspector3             realm::TableClusterTree::for_each_and_every_column(realm::util::FunctionRef<bool (realm::ColKey)>) const (zinspector3)
6  zinspector3             realm::Cluster::insert_row(unsigned long, realm::ObjKey, realm::FieldValues const&) (zinspector3)
7  zinspector3             realm::Cluster::insert(realm::ObjKey, realm::FieldValues const&, realm::ClusterNode::State&) (zinspector3)
8  zinspector3             realm::ClusterNodeInner::insert(realm::ObjKey, realm::FieldValues const&, realm::ClusterNode::State&)::$_1::operator()(realm::ClusterNode*, realm::ClusterNodeInner::ChildInfo&) const (zinspector3)
9  zinspector3             realm::ClusterNodeInner::insert(realm::ObjKey, realm::FieldValues const&, realm::ClusterNode::State&) (zinspector3)
10 zinspector3             realm::ClusterTree::insert_fast(realm::ObjKey, realm::FieldValues const&, realm::ClusterNode::State&) (zinspector3)
11 zinspector3             realm::ClusterTree::insert(realm::ObjKey, realm::FieldValues const&) (zinspector3)
12 zinspector3             realm::TableClusterTree::insert(realm::ObjKey, realm::FieldValues const&) (zinspector3)
13 zinspector3             realm::Table::create_object_with_primary_key(realm::Mixed const&, realm::FieldValues&&, realm::Table::UpdateMode, bool*) (zinspector3)
14 zinspector3             realm::Object realm::Object::create<realm::js::JsiVal, realm::js::NativeAccessor<realm::js::realmjsi::Types> >(realm::js::NativeAccessor<realm::js::realmjsi::Types>&, std::__1::shared_ptr<realm::Realm> const&, realm::ObjectSchema const&, realm::js::JsiVal, realm::CreatePolicy, realm::ObjKey, realm::Obj*) (zinspector3)
15 zinspector3             realm::js::RealmClass<realm::js::realmjsi::Types>::create(realm::js::JsiEnv, realm::js::JsiObj, realm::js::Arguments<realm::js::realmjsi::Types>&, realm::js::ReturnValue<realm::js::realmjsi::Types>&) (zinspector3)
16 zinspector3             facebook::jsi::Value realm::js::wrap<&realm::js::RealmClass<realm::js::realmjsi::Types>::create>(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) (zinspector3)
17 zinspector3             std::__1::function<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator()(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) const (function.h:505:16)
18 zinspector3             facebook::jsc::JSCRuntime::createFunctionFromHostFunction(facebook::jsi::PropNameID const&, unsigned int, std::__1::function<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>)::HostFunctionMetadata::call(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSValue*, unsigned long, OpaqueJSValue const* const*, OpaqueJSValue const**) (JSCRuntime.cpp:1158:13)
19 JavaScriptCore          JSC::callJSNonFinalObjectCallbackObject(JSC::JSGlobalObject*, JSC::CallFrame*)
20 JavaScriptCore          JSC::handleHostCall(JSC::JSGlobalObject*, JSC::CallFrame*, JSC::JSValue, JSC::CallLinkInfo*)
21 JavaScriptCore          _llint_link_call
22 JavaScriptCore          _llint_function_for_construct_arity_checkTagGateAfter
23 JavaScriptCore          _llint_function_for_construct_arity_checkTagGateAfter
24 JavaScriptCore          _llint_function_for_construct_arity_checkTagGateAfter
25 JavaScriptCore          _vmEntryToJavaScriptTrampoline
26 JavaScriptCore          JSC::Interpreter::executeCall(JSC::JSGlobalObject*, JSC::JSObject*, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&)
27 JavaScriptCore          JSC::profiledCall(JSC::JSGlobalObject*, JSC::ProfilingReason, JSC::JSValue, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&)
28 JavaScriptCore          _JSObjectCallAsFunction
29 zinspector3             facebook::jsc::JSCRuntime::call(facebook::jsi::Function const&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) (JSCRuntime.cpp:1260:14)
30 zinspector3             realm::js::Function<realm::js::realmjsi::Types>::call(realm::js::JsiEnv, realm::js::JsiFunc const&, realm::js::JsiObj const&, unsigned long, realm::js::JsiVal const*) (zinspector3)
31 zinspector3             realm::js::RealmClass<realm::js::realmjsi::Types>::write(realm::js::JsiEnv, realm::js::JsiObj, realm::js::Arguments<realm::js::realmjsi::Types>&, realm::js::ReturnValue<realm::js::realmjsi::Types>&) (zinspector3)
32 zinspector3             facebook::jsi::Value realm::js::wrap<&realm::js::RealmClass<realm::js::realmjsi::Types>::write>(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) (zinspector3)
33 zinspector3             std::__1::function<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator()(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) const (function.h:505:16)
34 zinspector3             facebook::jsc::JSCRuntime::createFunctionFromHostFunction(facebook::jsi::PropNameID const&, unsigned int, std::__1::function<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>)::HostFunctionMetadata::call(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSValue*, unsigned long, OpaqueJSValue const* const*, OpaqueJSValue const**) (JSCRuntime.cpp:1158:13)
35 JavaScriptCore          JSC::callJSNonFinalObjectCallbackObject(JSC::JSGlobalObject*, JSC::CallFrame*)
36 JavaScriptCore          JSC::handleHostCall(JSC::JSGlobalObject*, JSC::CallFrame*, JSC::JSValue, JSC::CallLinkInfo*)

Any thoughts on what could this be? Work arounds before recommending app reinstall?

Thanks.

cristianoccazinsp avatar Aug 13 '22 01:08 cristianoccazinsp

@tomduncalf @takameyer

We continue to see some more crashes related to corrupted databases that pretty much locks the user from using the app until a full reinstall. In addition to the above, here's a new one from today.

CrashReporter Key:  92f2f438b5f8e29473442d30cef9b759854f6d6b
Hardware Model:     iPhone7,2
Process:            zinspector3
Identifier:         com.zinspector.zinspector3
Version:            3.2.35
Role:               Foreground
OS Version:         iOS 12.5.5
Exception Type:     EXC_BAD_ACCESS 
Exception Subtype:  KERN_INVALID_ADDRESS


EXC_BAD_ACCESS: Attempted to dereference garbage pointer 0x309f04128b8.

0  zinspector3             realm::Array::destroy_deep(unsigned long, realm::Allocator&) (zinspector3)
1  zinspector3             realm::Array::destroy_children(unsigned long) (zinspector3)
2  zinspector3             realm::Table::remove_search_index(realm::ColKey) (zinspector3)
3  zinspector3             realm::ObjectStore::apply_schema_changes(realm::Transaction&, unsigned long long, realm::Schema&, unsigned long long, realm::SchemaMode, std::__1::vector<realm::SchemaChange, std::__1::allocator<realm::SchemaChange> > const&, std::__1::function<void ()>) (zinspector3)
4  zinspector3             realm::Realm::update_schema(realm::Schema, unsigned long long, std::__1::function<void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>, std::__1::function<void (std::__1::shared_ptr<realm::Realm>)>, bool) (zinspector3)
5  zinspector3             realm::_impl::RealmCoordinator::do_get_realm(realm::RealmConfig, std::__1::shared_ptr<realm::Realm>&, realm::util::Optional<realm::VersionID>, realm::util::CheckedUniqueLock&) (zinspector3)
6  zinspector3             realm::_impl::RealmCoordinator::get_realm(realm::RealmConfig, realm::util::Optional<realm::VersionID>) (zinspector3)
7  zinspector3             realm::Realm::get_shared_realm(realm::RealmConfig) (zinspector3)
8  zinspector3             realm::js::RealmClass<realm::js::realmjsi::Types>::create_shared_realm(realm::js::JsiEnv, realm::RealmConfig, bool, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, realm::js::Protected<realm::js::JsiVal>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, realm::js::Protected<realm::js::JsiVal> > > >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, realm::js::Protected<realm::js::JsiVal>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, realm::js::Protected<realm::js::JsiVal> > > > > > >&&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, realm::js::Protected<realm::js::JsiFunc>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, realm::js::Protected<realm::js::JsiFunc> > > >&&) (zinspector3)
9  zinspector3             realm::js::RealmClass<realm::js::realmjsi::Types>::constructor(realm::js::JsiEnv, realm::js::JsiObj, realm::js::Arguments<realm::js::realmjsi::Types>&) (zinspector3)
10 zinspector3             realm::js::realmjsi::ObjectWrap<realm::js::RealmClass<realm::js::realmjsi::Types> >::create_constructor(realm::js::JsiEnv)::{lambda(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)#1}::operator()(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) const (zinspector3)
11 zinspector3             std::__1::function<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>::operator()(facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long) const (function.h:505:16)
12 zinspector3             facebook::jsc::JSCRuntime::createFunctionFromHostFunction(facebook::jsi::PropNameID const&, unsigned int, std::__1::function<facebook::jsi::Value (facebook::jsi::Runtime&, facebook::jsi::Value const&, facebook::jsi::Value const*, unsigned long)>)::HostFunctionMetadata::call(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSValue*, unsigned long, OpaqueJSValue const* const*, OpaqueJSValue const**) (JSCRuntime.cpp:1158:13)
Screen Shot 2022-08-17 at 12 13 49

These all started right after upgrading to 11.0.0-rc.0 (from 10.20.0-beta.4 or 10.20.0-beta.5). Can we please get some priority review of this? A corruption this bad is really hurting our users and telling them to reinstall is being problematic as they lose important data.

In the interim, any work-around or suggestion would also be greatly appreciated.

cristianoccazinsp avatar Aug 17 '22 15:08 cristianoccazinsp

@cristianoccazinsp We're investigating this – do you have any other stack traces you could share?

tomduncalf avatar Aug 17 '22 16:08 tomduncalf

@tomduncalf for users getting locked with a crash, only the above two traces. We may get more detailed traces once apple sends it to us through XCode.

cristianoccazinsp avatar Aug 17 '22 17:08 cristianoccazinsp

@cristianoccazinsp We think it's possible this could be happening on migration. Can you provide any details on your migration strategy?

takameyer avatar Aug 18 '22 09:08 takameyer

Hi @takameyer ,

We haven't done any migration in a long time, besides w/e is done when the library version changes.

This is all the code related to creating/opening the realmdb:

Screen Shot 2022-08-18 at 11 26 55

cristianoccazinsp avatar Aug 18 '22 14:08 cristianoccazinsp

@cristianoccazinsp The reason for the question is that the stack trace has realm::Table::remove_search_index(realm::ColKey). Removing is also considered a schema change.

kneth avatar Aug 18 '22 14:08 kneth

That is strange, we haven't touched the schema definition in a long time, certainly didn't remove indexes, but I will do some more digging to see if an index changed at some point without upgrading the schema version. However, wouldn't that always return in a crash?

cristianoccazinsp avatar Aug 18 '22 15:08 cristianoccazinsp

@kneth I can confirm we haven't changed the db schema in the past 10 months, so I'm not sure where's the remove_search_index call coming from. Further, the change that was done 10 months ago was only a new field being added (no indexes).

cristianoccazinsp avatar Aug 19 '22 13:08 cristianoccazinsp

@cristianoccazinsp It is an interesting observation. If possible, we would like to get a copy of the Realm file in order to understand how it can trigger the code path in the stack trace.

kneth avatar Aug 19 '22 14:08 kneth

Hi @kneth , I don't think we have a good way to extract the database of the user having those persistent crashes, he also already re-installed the app as instructed. How else can I help? Would a local copy of a non-crashing db file work?

cristianoccazinsp avatar Aug 19 '22 14:08 cristianoccazinsp

@cristianoccazinsp If you sent us a file, we can run a couple of checks to see if something pops up. Moreover, we can send back what we believe is the schema and you can verify it. Not that I think it will give us much insight into this issue.

kneth avatar Aug 22 '22 07:08 kneth

@kneth I sent you the db file in an email. Let me know if you've got it and if you need anything else.

cristianoccazinsp avatar Aug 22 '22 15:08 cristianoccazinsp

@cristianoccazinsp Thank you. I have examined the file and replied by email.

kneth avatar Aug 23 '22 12:08 kneth

I've reported a similar issue here: https://github.com/realm/realm-js/issues/4891

Was there any resolution with this bug? Would at least like to prevent this from happening in the future.

@kneth let me know if you need any more realm file for debugging purposes

joze144 avatar Sep 09 '22 07:09 joze144

@joze144 Please see my comment

kneth avatar Sep 09 '22 08:09 kneth

@joze144 @cristianoccazinsp We have not been able to reproduce the issue. Do you observe the issue recently?

kneth avatar Oct 20 '22 11:10 kneth

@kneth i haven’t seen the issue lately.

cristianoccazinsp avatar Oct 20 '22 15:10 cristianoccazinsp

@cristianoccazinsp That's great news. I'll close the issue, and you are welcome to either create a new or reopen if it occurs again.

kneth avatar Oct 21 '22 13:10 kneth