Level / level

Universal abstract-level database for Node.js and browsers.
MIT License
1.55k stars 106 forks source link

Random "LEVEL_DATABASE_NOT_OPEN" errors caused by "LEVEL_IO_ERROR" #245

Open lucassilvas1 opened 5 months ago

lucassilvas1 commented 5 months ago

I have a little NodeJS app that reads notification LevelDB databases of Chromium browsers. To do that, since it only needs read access, I copy the database to the project directory (./db to be specific), and use level to access it. Since the purpose of the app is to watch for new notifications, I have a function checking the directory of the original database for changes. When a change is found, the app closes the level instance, deletes the copy database, makes a new copy and creates a new instance of level.

Now the problem is: seemingly randomly I'll get the error below when I call the open method of level:

C:\Users\Lucas\Javascript\chromium-notifier\node_modules\chromium-notification-retriever\dist\index.js:163
                throw new Error("Something went wrong while opening database", {
                      ^

Error: Something went wrong while opening database
    at #refresh (C:\Users\Lucas\Javascript\chromium-notifier\node_modules\chromium-notification-retriever\dist\index.js:163:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Retriever.retrieve (C:\Users\Lucas\Javascript\chromium-notifier\node_modules\chromium-notification-retriever\dist\index.js:178:9)
    at async onChange (C:\Users\Lucas\Javascript\chromium-notifier\node_modules\chromium-notification-retriever\dist\index.js:221:35) {
  [cause]: ModuleError: Database is not open
      at maybeOpened (C:\Users\Lucas\Javascript\chromium-notifier\node_modules\abstract-level\abstract-level.js:133:18)
      at C:\Users\Lucas\Javascript\chromium-notifier\node_modules\abstract-level\abstract-level.js:160:13
      at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
    code: 'LEVEL_DATABASE_NOT_OPEN',
    cause: [Error: IO error: RenameFile C:\Users\Lucas\Javascript\chromium-notifier\node_modules\chromium-notification-retriever\dist\db\36d5ce362e72a17b690f6cac0b40b70f/000091.dbtmp C:\Users\Lucas\Javascript\chromium-notifier\node_modules\chromium-notification-retriever\dist\db\36d5ce362e72a17b690f6cac0b40b70f/CURRENT: Access is denied.
    ] {
      code: 'LEVEL_IO_ERROR'
    }
  }
}

That error is thrown at this line here. It says it can't rename some temp file because access is denied. I'm not sure why that would be when I'm sure Node has write access to that folder, and if you look at that file I linked above, the only times the "copy database" directory is interacted with is when there's no level instance open. This is the only function that ends up interacting with the "copy database" directory, and it does so only after explicitly closing the instance, so I don't see how the files could be busy while trying to open the instance either.

I've been experiencing this intermittently for weeks now, and I have no idea what could be causing it, especially because the code is so simple, I've looked at it dozens of times by now.

Thanks.