Skip to content

fix(core): retry entire SQLite transaction on DatabaseBusy#34533

Merged
FrozenPandaz merged 1 commit intomasterfrom
fix-db-lock
Feb 23, 2026
Merged

fix(core): retry entire SQLite transaction on DatabaseBusy#34533
FrozenPandaz merged 1 commit intomasterfrom
fix-db-lock

Conversation

@FrozenPandaz
Copy link
Copy Markdown
Collaborator

Current Behavior

When multiple Nx processes (task hasher, daemon, workers) access the SQLite database concurrently, the NxDbConnection::transaction() method only retries the BEGIN step using the retry_db_operation_when_busy! macro. Operations executed inside the transaction and the COMMIT are not retried, so if the database is busy during those steps, the task crashes with:

Error: DB transaction operation error: SqliteFailure(Error { code: DatabaseBusy, extended_code: 5 }, Some("database is locked"))

This is particularly common during parallel task hashing with continuous tasks, where TaskDetails.recordTaskDetails() and RunningTasksService compete for write access.

Expected Behavior

The entire transaction (begin, execute, commit) is retried as a single unit when any step encounters a DatabaseBusy error. If the database is busy during the operation or commit, the transaction is automatically rolled back (via drop) and retried with the same exponential backoff used everywhere else.

Related Issue(s)

Previously the retry_db_operation_when_busy macro only wrapped
conn.transaction() (the BEGIN step). Operations inside the transaction
and the COMMIT were not retried, causing crashes when the DB was busy
during those steps. Now the entire begin-execute-commit sequence is
wrapped in a single retry macro call using and_then.
@FrozenPandaz FrozenPandaz requested review from a team as code owners February 20, 2026 19:00
@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud bot commented Feb 20, 2026

View your CI Pipeline Execution ↗ for commit b3a6ef2

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 15m 39s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 22s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗
nx-cloud record -- nx format:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-20 21:13:55 UTC

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 20, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit b3a6ef2
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6998af5131e2b8000803eb09
😎 Deploy Preview https://deploy-preview-34533--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 20, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit b3a6ef2
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6998af514c317b0008298aac
😎 Deploy Preview https://deploy-preview-34533--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@FrozenPandaz FrozenPandaz merged commit dd325d7 into master Feb 23, 2026
25 of 26 checks passed
@FrozenPandaz FrozenPandaz deleted the fix-db-lock branch February 23, 2026 17:29
FrozenPandaz added a commit that referenced this pull request Feb 26, 2026
## Current Behavior

When multiple Nx processes (task hasher, daemon, workers) access the
SQLite database concurrently, the `NxDbConnection::transaction()` method
only retries the BEGIN step using the `retry_db_operation_when_busy!`
macro. Operations executed inside the transaction and the COMMIT are not
retried, so if the database is busy during those steps, the task crashes
with:

```
Error: DB transaction operation error: SqliteFailure(Error { code: DatabaseBusy, extended_code: 5 }, Some("database is locked"))
```

This is particularly common during parallel task hashing with continuous
tasks, where `TaskDetails.recordTaskDetails()` and `RunningTasksService`
compete for write access.

## Expected Behavior

The entire transaction (begin, execute, commit) is retried as a single
unit when any step encounters a `DatabaseBusy` error. If the database is
busy during the operation or commit, the transaction is automatically
rolled back (via drop) and retried with the same exponential backoff
used everywhere else.

## Related Issue(s)

<!-- No public issue linked -->

(cherry picked from commit dd325d7)
FrozenPandaz added a commit that referenced this pull request Feb 26, 2026
## Current Behavior

When multiple Nx processes (task hasher, daemon, workers) access the
SQLite database concurrently, the `NxDbConnection::transaction()` method
only retries the BEGIN step using the `retry_db_operation_when_busy!`
macro. Operations executed inside the transaction and the COMMIT are not
retried, so if the database is busy during those steps, the task crashes
with:

```
Error: DB transaction operation error: SqliteFailure(Error { code: DatabaseBusy, extended_code: 5 }, Some("database is locked"))
```

This is particularly common during parallel task hashing with continuous
tasks, where `TaskDetails.recordTaskDetails()` and `RunningTasksService`
compete for write access.

## Expected Behavior

The entire transaction (begin, execute, commit) is retried as a single
unit when any step encounters a `DatabaseBusy` error. If the database is
busy during the operation or commit, the transaction is automatically
rolled back (via drop) and retried with the same exponential backoff
used everywhere else.

## Related Issue(s)

<!-- No public issue linked -->

(cherry picked from commit dd325d7)
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 1, 2026

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants