nx icon indicating copy to clipboard operation
nx copied to clipboard

Unable to set journal_mode: SqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file"))

Open wereHamster opened this issue 1 year ago • 48 comments

Current Behavior

nx fails to run on my self-hosted github runners when trying to upgrade from 20.0.3 to 20.0.5 with the error in $SUBJECT. No additional information is printed into the console. Any nx command seems to trigger that, such as nx run-many --target build.

Expected Behavior

Nx works, or at least prints a more useful message (eg. path to the database it's trying to access).

GitHub Repo

No response

Steps to Reproduce

It's a private repository, but I can try to reproduce if you think it'd help. I very much suspect it only affects certain type of self-hosted github runners, as the new version works on my local machine (macOS).

Nx Report

Node           : 20.15.1
OS             : linux-x64
Native Target  : x86_64-linux
pnpm           : 9.6.0

nx                 : 20.0.5
@nx/js             : 20.0.5
@nx/eslint         : 20.0.5
@nx/workspace      : 20.0.5
@nx/devkit         : 20.0.5
@nx/esbuild        : 20.0.5
@nx/eslint-plugin  : 20.0.5
@nx/next           : 20.0.5
@nx/react          : 20.0.5
@nx/web            : 20.0.5
@nx/webpack        : 20.0.5
typescript         : 5.6.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/next/plugin

Failure Logs

Run npx nx run-many --target build

NX Unable to set journal_mode: SqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file"))

Pass --verbose to see the stacktrace.

Error: Process completed with exit code 1.

Package Manager Version

No response

Operating System

  • [ ] macOS
  • [x] Linux
  • [ ] Windows
  • [ ] Other (Please specify)

Additional Information

No response

wereHamster avatar Oct 25 '24 16:10 wereHamster

Getting the same thing on Linux. Note that this looks similar to #28608 error

njsokol avatar Oct 25 '24 18:10 njsokol

In my case, each github runner has its own workspace and even running under its own user account, so there should not be any cross-workspace conflicts.

wereHamster avatar Oct 25 '24 21:10 wereHamster

The regression was introduced either in 20.0.4 or 20.0.5. I can try to narrow down which one it was. Looking at the changelog, nothing stands out (but there may have been changes not reflected in the changelog…).

Image

wereHamster avatar Oct 25 '24 21:10 wereHamster

Alright, regression was introduced in 20.0.4.

wereHamster avatar Oct 25 '24 21:10 wereHamster

Seeing this too

bjornharvold avatar Oct 27 '24 02:10 bjornharvold

Was getting this on an M2 Mac Unable to set journal_mode: SqliteFailure(Error { code: SystemIoFailure, extended_code: 522 }, Some("disk I/O error")) after upgrading to 20.0.6 from 20.0.0. After deleting the .nx folder the error went away as per the last comment here https://github.com/nrwl/nx/issues/28424

enchorb avatar Oct 28 '24 11:10 enchorb

@wereHamster if you run nx with the env NX_NATIVE_LOGGING=nx::native:db set, you should see where we're trying to open the database from.

Also, if you don't mind pasting the logs with NX_NATIVE_LOGGING here so that I can see the flow. Thank you.

Cammisuli avatar Oct 28 '24 13:10 Cammisuli

I'm getting a SqliteFailure "DatabaseBusy" error for the same command (after upgrading to NX 20, running on docker/linux). I don't know if it is related... I made a separate ticket since it is a different error code from the OP. https://github.com/nrwl/nx/issues/28665

cpierceworld avatar Oct 28 '24 14:10 cpierceworld

@wereHamster if you run nx with the env NX_NATIVE_LOGGING=nx::native:db set, you should see where we're trying to open the database from.

Also, if you don't mind pasting the logs with NX_NATIVE_LOGGING here so that I can see the flow. Thank you.

Setting NX_NATIVE_LOGGING=nx::native:db did not produce any additional logs (running on self hosted Nx Cloud).

We are getting the same error:

NX   Unable to set journal_mode: SqliteFailure(Error { code: DatabaseBusy, extended_code: 5 }, Some("database is locked"))

"useLegacyCache": true is set in nx.json.

minijus avatar Oct 31 '24 11:10 minijus

@minijus make sure to set NX_NATIVE_LOGGING before doing start-ci-run for Nx Cloud. The start command will be the step that collects the env vars to send to agents, not specific nx runs

Cammisuli avatar Nov 01 '24 14:11 Cammisuli

It seems the issue was addressed with v20.0.7 release.

minijus avatar Nov 03 '24 09:11 minijus

@Cammisuli setting that env. variable does not show any logs. I set it via env: top-level option in the github workflow so it's set when any job runs. And issue is still present in 20.0.7.

wereHamster avatar Nov 03 '24 22:11 wereHamster

The issue is still present in 20.0.7 and deleting .nx didn't help :(

DaSchTour avatar Nov 04 '24 15:11 DaSchTour

@wereHamster are you using Nx Agents?

Cammisuli avatar Nov 04 '24 21:11 Cammisuli

For me deleting the .nx folder did help and then command went ahead normally

saurabh-cimpress avatar Nov 05 '24 06:11 saurabh-cimpress

Not sure if this is a fix, but for us the issue was on the yarnrc.yml file.

We recently migrated to yarn berry (3.6.4) for one of our projects to use yarn workspaces & Lerna. But sometimes we need to go back to yarn classic since other projects do not support that version yet.

Anyways, we noticed that switching between versions will add the yarnPath config to the.yarnrc.yml file. After we removed that config lerna was working as expected. 🤷‍♂

Not sure if this is related with lerna or nx but hopefully this helps someone with the same issue 😅

raulgaf avatar Nov 05 '24 19:11 raulgaf

Chiming in. I was using a clean clone of a repo. I'd ask if anyone here is using the VS Code Nx Console (nrwl.angular-console) extension? I think it does something to mess up the cache during that initial loading of the workspace in VS Code.

Doing the clone and initial setup in a basic terminal seemed to get me past the point where things could get mangled.

djohnson-aperture avatar Nov 05 '24 20:11 djohnson-aperture

@wereHamster are you using Nx Agents?

No. I'm running Nx on self-hosted github action runners.

wereHamster avatar Nov 06 '24 20:11 wereHamster

Deleting the .nx folder does help, but its merely a temporary solution, error happens again eventually, and then you need to delete .nx folder again.

Erbenos avatar Nov 07 '24 20:11 Erbenos

Same issue here (on a Mac) after migrating from angular 17 to 18. and nx is on version 20.0.11. Deleting .nx folder or calling nx reset or nx repair isn't helping


deleting in web storm didn't work. After retrying with rm -rf .nx its working

LeLunZ avatar Nov 08 '24 10:11 LeLunZ

Folks here, can we try the latest version of Nx (20.0.12) to see if this is still reproducible?

Cammisuli avatar Nov 11 '24 14:11 Cammisuli

Folks here, can we try the latest version of Nx (20.0.12) to see if this is still reproducible?

Upgraded to 20.0.12 today and using github actions with namespace runners I am still getting the error

Full stack trace with --verbose

Run pnpm nx affected -t=test --base=origin/main --head=HEAD --exclude='tag:type:integration' --shard=2/2 --bail=1 --silent=true --verbose


Error: Unable to set journal_mode: DB pragma update error: SqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file"))
    at /home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/utils/db-connection.js:12:93
    at getEntryOrSet (/home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/utils/db-connection.js:26:17)
    at getDbConnection (/home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/utils/db-connection.js:12:24)
    at getTaskDetails (/home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/hasher/hash-task.js:19:84)
    at invokeTasksRunner (/home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/tasks-runner/run-command.js:367:56)
    at runCommandForTasks (/home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/tasks-runner/run-command.js:117:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/tasks-runner/run-command.js:105:29
    at async handleErrors (/home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/utils/handle-errors.js:9:24)
    at async runCommand (/home/runner/work/XXX/frontendnx/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@[email protected]__xbjtr5ucvm2hspey2expj3735e/node_modules/nx/src/tasks-runner/run-command.js:104:20)

kaylesworth avatar Nov 11 '24 18:11 kaylesworth

@kaylesworth lets try 20.0.13 now 🙂 thanks for your help!

Cammisuli avatar Nov 12 '24 12:11 Cammisuli

@kaylesworth lets try 20.0.13 now 🙂 thanks for your help!

@Cammisuli can confirm that it works in 20.0.13!

kaylesworth avatar Nov 12 '24 15:11 kaylesworth

We updated to the latest Nx v20.1.0 and still get an SqliteFailureError in our build: NX DB transaction operation error: SqliteFailure(Error { code: DatabaseBusy, extended_code: 5 }, Some("database is locked")) These errors started to occurr for us since Nx v20.0.4

tFaster avatar Nov 13 '24 08:11 tFaster

@tFaster where is this happening for you? Local dev machine? (macOS, Linux, Windows?). If locally do you have Nx Console installed? Or was this happening CI? Can you give me more details on what was happening before?

Cammisuli avatar Nov 13 '24 12:11 Cammisuli

For me it works on v20.1.0

mruknowme avatar Nov 13 '24 12:11 mruknowme

v20.1.0 not works for me, in macOS, without nx console (well I even do not know what’s it).

I’m off computer, I will provide more details later

ImSingee avatar Nov 13 '24 12:11 ImSingee

my nx.json:

{
  "useDaemonProcess": true,
  "targetDefaults": {
    "dev": {
      "dependsOn": ["^build"]
    },
    "build": {
      "dependsOn": ["^build", "check"]
    },
    "deploy": {
      "dependsOn": ["build", "^build", "check"]
    },
    "start": {
      "dependsOn": ["build", "^build"]
    },
    "check": {
      "dependsOn": ["^build"]
    }
  }
}

run nx, got the following error:

nx dev xxx


 NX   Running target dev for project xxx and 8 tasks it depends on:

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Daemon process terminated and closed the connection

Please rerun the command, which will restart the daemon.
If you get this error again, check for any errors in the daemon process logs found in: /xxx/.nx/workspace-data/d/daemon.log

 ELIFECYCLE  Command failed with exit code 1.

Process finished with exit code 1

daemon.log:

[NX Daemon Server] - 2024-11-13T16:00:47.171Z - Handled HASH_TASKS. Handling time: 16. Response time: 0.
<my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/utils/db-connection.js:12
    const connection = getEntryOrSet(dbConnectionMap, key, () => (0, native_1.connectToNxDb)(opts.directory, package_json_1.version, opts.dbName));
                                                                                            ^

Error: Unable to set journal_mode: DB pragma update error: SqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file"))
    at <my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/utils/db-connection.js:12:93
    at getEntryOrSet (<my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/utils/db-connection.js:26:17)
    at getDbConnection (<my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/utils/db-connection.js:12:24)
    at new TaskHistory (<my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/utils/task-history.js:11:91)
    at getTaskHistory (<my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/utils/task-history.js:48:23)
    at handleGetEstimatedTaskTimings (<my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/daemon/server/handle-task-history.js:24:59)
    at <my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/daemon/server/server.js:146:141
    at handleResult (<my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/daemon/server/server.js:172:22)
    at handleMessage (<my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/daemon/server/server.js:146:15)
    at <my project dir>/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/nx/src/daemon/server/server.js:72:15 {
  code: 'GenericFailure'
}


ImSingee avatar Nov 13 '24 16:11 ImSingee

Getting the same. Intel Mac ATM. NMX 19 and 20. Quite a persistent error. Usually have to run commands exactly three times to resolve the issue. Not sure why exactly three. The first two fail, third succeeds. Does not seem to matter how much time passes between runs. I can run three times in a row as fast as I can, or wait minutes between each. Always fails the first two, succeeds the third.

jrista avatar Nov 14 '24 06:11 jrista