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

Bug: Should soft fail and continue on fallocate error on AWS Lambda #1832

Closed
heri16 opened this issue May 28, 2018 · 16 comments · Fixed by #2178
Closed

Bug: Should soft fail and continue on fallocate error on AWS Lambda #1832

heri16 opened this issue May 28, 2018 · 16 comments · Fixed by #2178

Comments

@heri16
Copy link

heri16 commented May 28, 2018

Goals

Trying to run realm-js on nodejs 8.10 AWS Lambda.

Expected Results

Should be able to open a realm path on /tmp

Actual Results

{
    "errorMessage": "posix_fallocate() failed: Operation not permitted",
    "errorType": "Error",
    "stackTrace": [
        "Function.open (/var/task/node_modules/realm/lib/extensions.js:72:47)",
        "exports.handler (/var/task/api/realm.js:45:25)"
    ]
}

Steps to Reproduce

  1. Create a serverless framework project.
  2. npm install realm.
  3. Deploy the function below: sls deploy -f realm
  4. Try invoking the function below: sls invoke -f realm --data "{'test': 'ok'}"

Code Sample

'use strict'

// See: https://realm.io/docs/javascript/latest/#getting-started

const process = require('process')

const debug = require('debug')('realm')
const Realm = require('realm')

const CarSchema = {
  name: 'Car',
  properties: {
    make: 'string',
    model: 'string',
    miles: { type: 'int', default: 0 },
  },
}

// Define new ES6 class
class Person {
  get fullName() {
    return `${this.firstName} ${this.lastName}`
  }

  static get schema() {
    return {
      name: 'Person',
      properties: {
        name: 'string',
        birthday: 'date',
        cars: 'Car[]',
        picture: 'data?', // optional property
      },
    }
  }
}

exports.handler = async (event, context) => {
  console.log('Received event', JSON.stringify(event, 3)) // eslint-disable-line no-console
  console.log('Received context', JSON.stringify(context, 3)) // eslint-disable-line no-console

  let realm
  try {
    process.chdir('/tmp')
    realm = await Realm.open({
      path: '/tmp/cars.realm',
      inMemory: true,
      schema: [CarSchema, Person],
    })
  } catch (err) {
    console.error(err) // eslint-disable-line no-console
    throw err
  }

  // Create Realm objects and write to local storage
  realm.write(() => {
    const myCar = realm.create('Car', {
      make: 'Honda',
      model: 'Civic',
      miles: 1000,
    })
    myCar.miles += 20 // Update a property value
  })

  // Query Realm for all cars with a high mileage
  const cars = realm.objects('Car').filtered('miles > 1000')

  // Will return a Results object with our 1 car
  debug('cars.length:', cars.length) // => 1

  // Add another car
  realm.write(() => {
    realm.create('Car', {
      make: 'Ford',
      model: 'Focus',
      miles: 2000,
    })
  })

  // Query results are updated in realtime
  debug('cars.length:', cars.length) // => 2
  console.log('cars.length:', cars.length) // eslint-disable-line no-console

  return {
    statusCode: 200,
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(cars),
  }
}## Version of Realm and Tooling
  • Realm JS SDK Version: ? Latest
  • Node or React Native: ? Nodejs v8.10
  • Client OS & Version: AWS Lambda Runtime
  • Which debugger for React Native: None
@kneth
Copy link
Contributor

kneth commented Jun 11, 2018

Sorry for the late response. The only thing I can suggest is that you check the permissions of /tmp.

@heri16
Copy link
Author

heri16 commented Jun 12, 2018

I am sorry, this is not a user-help issue. There is no benefit from checking the permissions of /tmp when the PaaS provider is the one that controls it.

Realm-core needs to be fixed to dynamically account for environments that do not support sparse files.

@kneth
Copy link
Contributor

kneth commented Jun 12, 2018

@heri16 Thanks for the hint on sparse files.

@finnschiermer Can you enlighten us on sparse files and mmap()?

@kneth
Copy link
Contributor

kneth commented Jun 13, 2018

@heri16 Do you know which file system /tmp is? You can see it from the output of mount?

@jeddWebill
Copy link

Hi Is there any update on this?

@heri16
Copy link
Author

heri16 commented Sep 12, 2018

@kneth it it the ephemeral filesystem provided on AWS Lambda.

@heri16
Copy link
Author

heri16 commented Sep 12, 2018

Instead of doing of programming for every type of POSIX filesystem out there, should do defensive programming instead.

@kneth
Copy link
Contributor

kneth commented Dec 14, 2018

@heri16 @jeddWebill @emanuelez

We have a fix coming up in #2178. I plan to release it as v2.22.0-beta.1 but I will notify you when happens.

@kneth
Copy link
Contributor

kneth commented Dec 15, 2018

@heri16 @jaggs6 I have release a fix for AWS Lambda as v2.22.0-beta.1. I kindly ask you to try it out and tell me if it works out for you. If it does, I will release v2.22.0 Wednesday or Thursday next week.

@kneth
Copy link
Contributor

kneth commented Dec 17, 2018

v2.22.0-beta.1 doesn't fix it. But I don't think in it in our code. Running fallocate -l 1M foo.img give the same error.

@kneth kneth reopened this Dec 18, 2018
@bmunkholm bmunkholm added T-Bug and removed T-Help labels Sep 5, 2019
@bmunkholm bmunkholm changed the title Bug: Should soft fail and continue on fallocate error Bug: Should soft fail and continue on fallocate error on AWS Lambda Sep 5, 2019
@mithunph
Copy link

mithunph commented Sep 8, 2019

Hi @kneth @bmunkholm ,
Is the issue fixed now? I am still facing the same issue

@kneth
Copy link
Contributor

kneth commented Sep 9, 2019

@mithunph Unfortunately not. AWS support hasn't been able to explain why it doesn't work.

@mithunph
Copy link

mithunph commented Sep 9, 2019

Hi @kneth ,
Will it work atleast under EC2 instance instead of AWS Lambda(serverless)?

@bmunkholm
Copy link
Contributor

@mithunph Absolutely. Our whole Cloud is running there :-)

@mithunph
Copy link

mithunph commented Sep 9, 2019

Thanks @bmunkholm @kneth

@kneth
Copy link
Contributor

kneth commented Oct 26, 2021

We have a proper fix in #4023

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants