Skip to content

Frequent random crashes during fast queries on encrypted Realm files. Occurs in v12/v20; no issues in v11. #7084

@jooy2

Description

@jooy2

How frequently does the bug occur?

Always

Description

Hello,
Recently while using Realm.js, I encountered a situation where I needed to upgrade Realm. The version I was originally using was 11.10.2.

After upgrading Realm to v20 (the current community version), I confirmed that several core issues were resolved, but the following problems began to occur: (CRASH OUTPUT ATTACHED BELOW)

This issue primarily occurs when multiple queries are running rapidly. What's clear is that my Electron app can open multiple windows, and crashes happen more frequently when multiple windows are open.

Crashes also occur less frequently when only a single window is open. Sometimes it crashes immediately upon opening a window (if a query is already running in the previous window), or it crashes while queries are running in both windows after opening them.

One thing is certain:

  • This issue does not occur at all in V11.
  • This issue occurs on all operating systems. (Desktop-web app only; I haven't verified React + React Native.)
  • Furthermore, the problem only reproduces when the data file (.realm) is encrypted.
  • I use only the local database without Atlas Device Sync service.

To summarize:

  • Realm 11.0.0 ~ 11.10.2 (Any settings) -> No issues
  • Realm 11.0.0 ~ 12.15.0 ~ 20.2.0 (Without Encryption) -> No issues
  • Realm 12.0.0 ~ 12.15.0 (With Encryption) -> Oops
  • Realm 20.0.0 ~ 20.2.0 (With Encryption) -> Oops

Additionally, since my environment uses the same encryptionKey and all realm settings, it is not an issue with the key used for encryption.

   // Realm configuration used for the reproduction
    const realm = await new Realm({
      schema: [TempData, RandomValues],
      path: await ipcRenderer.invoke('onGetDatabasePath'),
      encryptionKey: new Uint8Array([
        65, 15, 0, 134, 56, 223, 76, 174, 39, 130, 6, 44, 210, 57, 181, 149, 77, 14, 24, 230, 252,
        2, 250, 89, 149, 61, 209, 98, 163, 94, 140, 68, 9, 117, 102, 216, 105, 69, 99, 79, 25, 146,
        110, 36, 107, 223, 147, 50, 227, 135, 249, 223, 16, 85, 47, 36, 168, 149, 91, 58, 238, 16,
        49, 123
      ]).buffer,
      schemaVersion: 2
    })

All problems occur with random probability, but they happen more easily than one might expect.
After a crash occurs, restarting the app will not corrupt the Realm file, and it can be used normally again.

I would appreciate it if you could kindly review this issue.

Regards,

Stacktrace & log output

libc++abi: terminating due to uncaught exception of type realm::util::DecryptionFailed: Decryption failed: page 0 in file of size 270336 failed the HMAC check. Either the encryption key is incorrect or data is corrupted
 0   realm.node                          0x000000010d847224 _ZN5realm4util16DecryptionFailed19get_message_with_btENSt3__117basic_string_viewIcNS2_11char_traitsIcEEEE + 56
 1   realm.node                          0x000000010d8475bc _ZN5realm4util16DecryptionFailedC2ERKNSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEE + 56
 2   realm.node                          0x000000010d857da0 _ZN5realm4util20EncryptedFileMapping22throw_decryption_errorEmNSt3__117basic_string_viewIcNS2_11char_traitsIcEEEE + 152
 3   realm.node                          0x000000010d84658c _ZN5realm4util20EncryptedFileMapping12refresh_pageEmb + 376
 4   realm.node                          0x000000010d846ef0 _ZN5realm4util20EncryptedFileMapping12read_barrierEPKvmb + 224
 5   realm.node                          0x000000010d533634 _ZNK5realm9Allocator18translate_criticalEPNS0_14RefTranslationEm + 268
 6   realm.node                          0x000000010d752f34 _ZN5realm5Group6attachEmbbmy + 188
 7   realm.node                          0x000000010d758550 _ZN5realm5Group16advance_transactEmPNS_4util11InputStreamEb + 1084
 8   realm.node                          0x000000010d5d7404 _ZN5realm11Transaction21internal_advance_readIN12_GLOBAL__N_120TransactLogValidatorEEEbPT_NS_9VersionIDERNS_5_impl7HistoryEb + 1680
 9   realm.node                          0x000000010d5d3c54 _ZN5realm5_impl11transaction7advanceERKNSt3__110shared_ptrINS_11TransactionEEEPNS_14BindingContextEONS0_15NotifierPackageE + 384
 10  realm.node                          0x000000010d5ccd84 _ZN5realm5_impl16RealmCoordinator16advance_to_readyERNS_5RealmE + 848
 11  realm.node                          0x000000010d5935c4 _ZN5realm5Realm6notifyEv + 328
 12  realm.node                          0x000000010d5da1ec _ZN5realm4util14UniqueFunctionIFvvEE12SpecificImplIZNS_5_impl17WeakRealmNotifier6notifyEvE3$_0E4callEv + 48
 13  realm.node                          0x000000010d5dac0c _ZN5realm4util15InvocationQueue10invoke_allEv + 96
 14  Electron Framework                  0x0000000111f32598 uv__async_fork + 772
 15  Electron Framework                  0x0000000111f44810 uv__io_poll + 1336
 16  Electron Framework                  0x0000000111f32a64 uv_run + 376
 17  Electron Framework                  0x00000001120d4128 _ZN4node6sqlite19UserDefinedFunction8xDestroyEPv + 33648
 18  Electron Framework                  0x000000010f7bb128 temporal_rs_PlainTime_second + 1588
 19  Electron Framework                  0x000000010f7ba5d8 _ZNK4node14PrincipalRealm42primordials_safe_weak_set_prototype_objectEv + 68632
 20  Electron Framework                  0x0000000111dd7778 _ZNK2v88internal8compiler23CompilationDependencies25CompilationDependencyHashclEPKNS1_21CompilationDependencyE + 439196
 21  Electron Framework                  0x0000000110d0bdd8 _ZN2v88internal8compiler23CompilationDependencies29DependOnEmptyContextExtensionENS1_12ScopeInfoRefE + 25104
 22  Electron Framework                  0x0000000110e3dae4 _ZN2v814ScriptCompiler14StartStreamingEPNS_7IsolateEPNS0_14StreamedSourceENS_10ScriptTypeENS0_14CompileOptionsEPFbiPvES7_ + 9880
 23  Electron Framework                  0x00000001111fdba8 _ZNK4node9inspector8protocol5Value16AppendSerializedEPNSt4__Cr6vectorIhNS3_9allocatorIhEEEE + 27824
 24  Electron Framework                  0x00000001111fb70c _ZNK4node9inspector8protocol5Value16AppendSerializedEPNSt4__Cr6vectorIhNS3_9allocatorIhEEEE + 18452
 25  Electron Framework                  0x00000001111fac24 _ZNK4node9inspector8protocol5Value16AppendSerializedEPNSt4__Cr6vectorIhNS3_9allocatorIhEEEE + 15660
 26  Electron Framework                  0x000000011147a118 _ZN2v814ObjectTemplate10SetHandlerERKNS_33NamedPropertyHandlerConfigurationE + 64496
 27  Electron Framework                  0x0000000111479ad8 _ZN2v814ObjectTemplate10SetHandlerERKNS_33NamedPropertyHandlerConfigurationE + 62896
 28  Electron Framework                  0x0000000111f44f4c ElectronMain + 124
 29  Electron Helper (Renderer)          0x0000000104d50efc Electron Helper (Renderer) + 36604
 30  dyld                                0x0000000189251d54 start + 7184

Can you reproduce the bug?

Always

Reproduction Steps

I have created a repository where you can reproduce this issue.

https://github.com/jooy2/issue-electron-vue-realm

After receiving the repository, run the following command.

$ npm i
$ npm run dev

This project allows you to run tests that infinitely repeat queries to add and delete dummy data.

When you press the 'Start test' button in the app, the quick query runs repeatedly. After that, you can open a new window using 'Open new window'.

Leave the window running the query open, open a new window, and run the query again in the newly opened window.
After that, if you close a specific window, reopen windows, or keep the query running, the app may crash intermittently.

Below is the reproduced video. Issues occur at approximately 0:16 and 1:20.

realm-issue.mp4

Version

20.2.0 (After v12, No issue occur 11.10.2)

What services are you using?

Local Database only

Are you using encryption?

Yes

Platform OS and version(s)

macOS (issue persist on all os)

Build environment

  • Node.js 22.14.0
  • Vue 3.5.x
  • Webpack 5
  • Electron.js (latest)

Cocoapods version

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions