simonlast / node-persist

Super-easy persistent data structures in Node.js
MIT License
719 stars 78 forks source link

node-persist error sometimes makes the application to crash #138

Closed ndozhh closed 1 year ago

ndozhh commented 2 years ago

Hello, any idea what is the cause of this error? My application is deployed in Vercel, and sometimes it crashes and generates this error.

2022-07-19T04:35:38.321Z    c2e38db0-e42e-4b5c-ac95-f50ec717eb7e    ERROR   Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: ENOENT: no such file or directory, mkdir '/var/task/.node-persist'","reason":{"errorType":"Error","errorMessage":"ENOENT: no such file or directory, mkdir '/var/task/.node-persist'","code":"ENOENT","errno":-2,"syscall":"mkdir","path":"/var/task/.node-persist","stack":["Error: ENOENT: no such file or directory, mkdir '/var/task/.node-persist'"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: ENOENT: no such file or directory, mkdir '/var/task/.node-persist'","    at process.<anonymous> (file:///var/runtime/index.mjs:775:15)","    at process.emit (node:events:539:35)","    at process.emit (/var/task/node_modules/source-map-support/source-map-support.js:516:21)","    at emit (node:internal/process/promises:140:20)","    at processPromiseRejections (node:internal/process/promises:274:27)","    at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
[ERROR] [1658205338322] LAMBDA_RUNTIME Failed to post handler success response. Http response code: 400.
RequestId: 4ba770e1-f539-4c3c-b041-3fb60360f0ac Error: Runtime exited with error: exit status 128
Runtime.ExitError

Thank you!

victorcsciandt commented 2 years ago

Anyone had a chance to look at this? I'm facing the same issue on my application

akhoury commented 1 year ago

could be related https://github.com/vercel/vercel/discussions/5066#discussioncomment-54268 in vercel.json you might need to include the .node-persist dir

this is NOT tested I do not have a vercel host

{
  "functions": {
    "app.js": { // <-- not sure about this value here

      "includeFiles": "/var/task/.node-persist/**" // or "includeFiles": "/var/task/.node-persist/**" 
    }
  }
}
jswent commented 1 year ago

I included the path for all my serverless functions but I'm still getting the same error. Any help is greatly appreciated.

Error message:

[Error: ENOENT: no such file or directory, mkdir '/var/task/.node-persist'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: '/var/task/.node-persist'
}
[Error: ENOENT: no such file or directory, mkdir '/var/task/.node-persist'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: '/var/task/.node-persist'
}
RequestId: 0e2a43fd-dcea-4e77-9fcb-a244c1262e07 Error: Runtime exited with error: exit status 1
Runtime.ExitError

vercel.json:

{
  "functions": {
    "pages/api/**/*.js": {
      "includeFiles": "/var/task/.node-persist/**"
    }
  }
}
akhoury commented 1 year ago

this error suggests that /var/task/ dir does not exists, it's failing to create .node-persist dir, using mkdir. this a system issue, or maybe vercel doesn't let you create directories or maybe you should create it in your project, put a .gitkeep in it and "includeFiles": ".node-persist/**" I really can't test this to be honest.

jswent commented 1 year ago

Yeah, turns out vercel doesn't let you use that path even if you explicitly include it. So I switched my storage dir to

await storage.init({ dir: '/tmp/node-persist', logging: true, ttl: 60000  })

and now it's working. Hopefully this solves it going forward.

akhoury commented 1 year ago

Great!