realm / realm-js

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

Failed to open Realm file at path '/data/data/<our_package>/files/default.realm': Failed to memory buffer:Invalid top array size (ref: 5104, array size: 0) file size: 0, read lock size: none, read lock version: none #6852

Open davidtjones02 opened 3 months ago

davidtjones02 commented 3 months ago

How frequently does the bug occur?

Always

Description

What happened Samsung Note 20 Ultra 5G User of our React-Native application cannot load into app. It falls back to our Sentry Error Boundary as soon as they launch it.

Sentry raised the error to us as Failed to open Realm file at path '/data/data//files/default.realm': Failed to memory buffer:Invalid top array size (ref: 5104, array size: 0) file size: 0, read lock size: none, read lock version: none

What did we expect? User to be brought to the login page of our application.

Additional context We have various other users using Samsung devices, I unfortunately do not have the Note 20 specifically, however have tested on an "Samsung Galaxy A21s" and have not been able to replicate.

I was also not able to replicate it and on two different Android emulator SDK versions API 33 (Android 13 Tiramusu, which is the same as the affected user) and API 30 (Android 30)

I did notice one permission differences on their android device, however even after connecting my emulator to adb and running pm revoke <our_package> android.permission.READ however that gave me an "Unknown permission" error

Sentry Reported Permissions for affected user:

{
  ACCESS_MEDIA_LOCATION: not_granted,
  ACCESS_NETWORK_STATE: granted,
  ACCESS_WIFI_STATE: granted,
  BADGE_COUNT_READ: not_granted,
  BADGE_COUNT_WRITE: not_granted,
  BIND_GET_INSTALL_REFERRER_SERVICE: granted,
  BROADCAST_BADGE: not_granted,
  CAMERA: not_granted,
  CHANGE_BADGE: not_granted,
  DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION: granted,
  FOREGROUND_SERVICE: granted,
  FOREGROUND_SERVICE_MEDIA_PLAYBACK: not_granted,
  INTERNET: granted,
  MODIFY_AUDIO_SETTINGS: granted,
  POST_NOTIFICATIONS: not_granted,
  PROVIDER_INSERT_BADGE: not_granted,
- READ: not_granted,
+ READ: granted,
  READ_APP_BADGE: not_granted,
  READ_EXTERNAL_STORAGE: not_granted,
  READ_MEDIA_AUDIO: not_granted,
  READ_MEDIA_IMAGES: not_granted,
  READ_MEDIA_VIDEO: not_granted,
  READ_MEDIA_VISUAL_USER_SELECTED: not_granted,
  READ_SETTINGS: not_granted,
  RECEIVE: granted,
  RECEIVE_BOOT_COMPLETED: granted,
  RECORD_AUDIO: not_granted,
  SYSTEM_ALERT_WINDOW: not_granted,
  UPDATE_BADGE: not_granted,
  UPDATE_COUNT: not_granted,
  UPDATE_SHORTCUT: not_granted,
  VIBRATE: granted,
  WAKE_LOCK: granted,
  WRITE: not_granted,
  WRITE_EXTERNAL_STORAGE: not_granted,
  WRITE_SETTINGS: not_granted
}

I do wonder if this could be some sort of permission/os related write access issue but unfortunately I'm not familiar enough to know this. Happy to provide any extra details/context that you might need.

Stacktrace & log output

Error: Failed to open Realm file at path '/data/data/<our_package>/files/default.realm': Failed to memory buffer:Invalid top array size (ref: 5104, array size: 0) file size: 0, read lock size: none, read lock version: none
  at Realm_get_shared_realm(native)
  at mixedToBinding(node_modules/realm/dist/bundle.react-native.js:4298:48)
  at List#constructor(node_modules/realm/dist/bundle.react-native.js:5878:28)
  at parse(node_modules/uuid/dist/parse.js:28:9)
  at updateSlot(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:3070:14)
  at shouldConstruct(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:9189:26)
  at M(node_modules/react/cjs/react.production.min.js:15:294)
  at generateUUID(node_modules/uuid/dist/v35.js:56:16)
  at trackUsedThenable(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:2733:7)
  at ResponderTouchHistoryStore.recordTouchTrack(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:306:20)
  at recursivelyTraverseLayoutEffects(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:7351:32)
  at commitMutationEffectsOnFiber(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:7105:45)
  at commitMutationEffectsOnFiber(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:7095:7)
  at findCurrentFiberUsingSlowPath(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:1346:9)
  at ResponderEventPlugin.extractEvents(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:553:24)
  at <global>(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:147:15)
  at <global>(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:378:18)
  at flushPassiveEffects(node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js:8575:38)
  at apply(native)
  at __callFunction(node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:435:24)
  at invokeCallbackAndReturnFlushedQueue(node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:123:17)
  at __guard(node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:365:9)
  at __guard$argument_0(node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:113:35

Viewing the full stack trace on sentry also mentions these bits specifically for MongoDB Realm
Stack Trace, I can provide the remainder but it appears to just be minified react native logic.

native in Realm_get_shared_realm
node_modules/realm/dist/bundle.react-native.js in mixedToBinding at line 4298:48

            }
        }
        // Convert typed arrays to an `ArrayBuffer`
        for (const TypedArray of TYPED_ARRAY_CONSTRUCTORS) {
            if (value instanceof TypedArray) {
                return value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength);
            }
        }
        // Rely on the binding for any other value
        return value;
    }
node_modules/realm/dist/bundle.react-native.js in List#constructor at line 5878:28

            throw new IllegalConstructorError("List");
        }
        super(realm, internal.asResults(), helpers);
        // Getting the `objectSchema` off the internal will throw if base type isn't object
        const baseType = this.results.type & ~960 /* binding.PropertyType.Flags */;
        const isEmbedded = baseType === 7 /* binding.PropertyType.Object */ && internal.objectSchema.tableType === 1 /* binding.TableType.Embedded */;
        Object.defineProperty(this, "internal", {
            enumerable: false,
            configurable: false,
            writable: false,
            value: internal,

react_native_context
react_native_context
component_stack
in Unknown in RNGestureHandlerRootView in GestureHandlerRootView in RNCSafeAreaProvider in SafeAreaProvider in ErrorBoundary in App in ReactNativeProfiler in RCTView in Unknown in __Sentry.TouchEventBoundary in RootApp in RCTView in Unknown in AppContainer
expo
true
fabric
false
hermes_debug_info
false
hermes_version
for RN 0.74.1
js_engine
hermes
react_native_version
0.74.2
turbo_module
false

Can you reproduce the bug?

No

Reproduction Steps

Device Information

Device: Galaxy Note20 Ultra 5G
Storage: > 100 GBs remaining
Low Memory: false

Realm Config

import { createRealmContext } from "@realm/react";

const realmConfig: Realm.Configuration = {
  schema: [
 // schemas here
  ],
};

export const Realm = createRealmContext(realmConfig);

export const Realm = createRealmContext(realmConfig);

MinimalContext Featire Integration

export const CacheContextProvider = ({ children }: { children: ReactNode }) => {
  const { useRealm } = Realm;

  const realm = useRealm();

  const contextValue = useMemo(
    () => ({
     realm,
   // various other utilities/functions stored here
    }),
    []
  );

  return (
    <CacheContext.Provider value={contextValue}>
      {children}
    </CacheContext.Provider>
  );
};

Minimal App.tsx

    <ErrorBoundary FallbackComponent={ErrorScreen}>
      <SafeAreaProvider>
        <GestureHandlerRootView style={{ flex: 1 }}>
          <Realm.RealmProvider>
            <CacheContextProvider>
                 {// app goes here }
            </CacheContextProvider>
          </Realm.RealmProvider>
        </GestureHandlerRootView>
      </SafeAreaProvider>
    </ErrorBoundary>

Explicit Permissions in app.json "permissions": [ "android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.ACCESS_MEDIA_LOCATION", "android.permission.RECORD_AUDIO" ]

Version

12.3.0

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android 13 & API 33, React Native

Build environment

"expo": "^51.0.1",
"react-native": "0.74.1",
"realm": "^12.3.0",
"@realm/react": "^0.6.1",

Cocoapods version

No response

sync-by-unito[bot] commented 3 months ago

➤ PM Bot commented:

Jira ticket: RJS-2891

davidtjones02 commented 2 months ago

Any thoughts? Issue is still present 🙁