Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realm got error Read-only file system with android 8.1 #4450

Closed
lytrunghieu opened this issue Mar 29, 2022 · 13 comments
Closed

Realm got error Read-only file system with android 8.1 #4450

lytrunghieu opened this issue Mar 29, 2022 · 13 comments
Assignees
Labels
O-Community T-Bug Waiting-For-Reporter Waiting for more information from the reporter before we can proceed

Comments

@lytrunghieu
Copy link

lytrunghieu commented Mar 29, 2022

How frequently does the bug occur?

All the time

Description

I created new react native project and install realm. When I call open connection then I got error "Read-only file system", it is working on android version less 8.1.
Note: it still working on android 8.1 if I use default path of realm.

my package.json:

{
  "name": "awesomeproject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "17.0.2",
    "react-native": "0.67.4",
    "realm": "^10.14.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "7.14.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.66.2",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

Code for open connection realm:

const AppInfoSchema = {
  name: 'AppInfoRealmSave',
  properties: {
    packageName: 'string',
    isPostponeLater: 'bool',
    isUpdateUsingLauncher: 'bool',
  },
  primaryKey:'packageName'
};

 Realm.open({
      path: "/storage/emulated/0/AppUpdate/app_update.realm",
      schema: [AppInfoSchema],
      schemaVersion:42
})

I appreciate any help.

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

No response

Version

10.14.0

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Android

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

@kraenhansen
Copy link
Member

Would it be a possible solution to copy the realm to the App specific storage? You might be able to use something like https://www.npmjs.com/package/react-native-fs#API to get the path of that directory.

@lytrunghieu
Copy link
Author

Hi @kraenhansen

I need to share realm file with other app. If I save file realm for only specific app then other app can not access realm file. It is weird, because this bug is only exist on android version larger than 8.0.

@kraenhansen
Copy link
Member

@lytrunghieu I imagine your app has to ask the OS for permission to write to this directory. Are you using any of the Android APIs to request access to the shared storage?

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Mar 29, 2022
@lytrunghieu
Copy link
Author

@kraenhansen

Yes, I have added permission in AndroidManifest.xml

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

And in app I requested permission as well

   const grantedWrite = await PermissionsAndroid.requestMultiple([
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
          PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE]);

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Mar 29, 2022
@kraenhansen
Copy link
Member

kraenhansen commented Mar 30, 2022

@lytrunghieu to be honest, I'm clueless on what might be happening here then.

It will require further investigations.
Getting a minimal reproduction (a simple GitHub repository showing this error) would be a great help!

@lytrunghieu
Copy link
Author

@kraenhansen Have you try reproduce on android 8.1 ?

@kraenhansen
Copy link
Member

Nope. I havn't reproduced this yet. My expectation is that the security model was change / tightened with Android 8.1 which is why Realm core can't open the Realm in write-mode.

@tomduncalf
Copy link
Contributor

Hi @lytrunghieu, were you able to create a minimal repro of this issue?

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Apr 13, 2022
@realm realm deleted a comment from sync-by-unito bot May 12, 2022
@kneth
Copy link
Contributor

kneth commented May 30, 2022

I am closing the issue due to no reply back. Please comment and reopen the issue if needed.

@thucnguyenpfs
Copy link

thucnguyenpfs commented Mar 21, 2023

Hello, I have the same problem but on aws nodejs. There was an error in the log.

    "errorType": "RealmError",
    "errorMessage": "Failed to create directory at '/var/task/mongodb-realm/': Read-only file system",
    "code": "PermissionDenied",
    "name": "RealmError",
    "stack": [
        "RealmError: Failed to create directory at '/var/task/mongodb-realm/': Read-only file system",
        "    at /var/task/src/handler.js:1:1555",
        "    at Generator.next (<anonymous>)",
        "    at /var/task/src/handler.js:1:1234",
        "    at new Promise (<anonymous>)",
        "    at o (/var/task/src/handler.js:1:979)",
        "    at Runtime.t.creditLoyalty [as handler] (/var/task/src/handler.js:1:1464)",
        "    at Runtime.handleOnceNonStreaming (/var/runtime/Runtime.js:74:25)"
    ]

My code


  let creditAvailables, cogintoToken;
  try {
    const appLogged = await app.logIn(
      Realm.Credentials.apiKey(process.env.REALM_API_KEY)
    );

    const creditAvailablePromise = await appLogged.functions.getCreditAvailableByBrand({
        brandShopCode: partnerCode,
      });
   } catch (err) {
    console.error('Failed to log in', err);
  }

Do you have any idea?

@kneth
Copy link
Contributor

kneth commented Mar 22, 2023

@thucnguyenpfs It is unrelated to the original issue, and creating a new issue is the best approach.

Said that, /var/task/ is probably read-only on your server, and you should either make the directory writable or use a directory with fewer restrictions.

@sinhgithub
Copy link

why this issue is closed :(

@nirinchev
Copy link
Member

Because the author didn't reply with repro case. If you're experiencing a similar problem, file a new issue and fill in the template.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
O-Community T-Bug Waiting-For-Reporter Waiting for more information from the reporter before we can proceed
Projects
None yet
Development

No branches or pull requests

7 participants