fix: scan status race - #504
Merged
Merged
Conversation
ansgarlichter
requested a deployment
to
pr-approval
July 28, 2026 20:03 — with
GitHub Actions
Waiting
ansgarlichter
temporarily deployed
to
pr-approval
July 28, 2026 20:06 — with
GitHub Actions
Inactive
ansgarlichter
temporarily deployed
to
pr-approval
July 29, 2026 07:26 — with
GitHub Actions
Inactive
Contributor
Author
I guess that the tests failures related to these errors, are not related to my changes. On main the same test runs seem to fail as well. |
KoblerS
force-pushed
the
fix/scanning-race
branch
from
July 30, 2026 08:54
c200b0e to
8a18141
Compare
eric-pSAP
approved these changes
Jul 30, 2026
eric-pSAP
enabled auto-merge (squash)
July 30, 2026 09:11
KoblerS
disabled auto-merge
July 30, 2026 13:58
KoblerS
enabled auto-merge (squash)
July 30, 2026 13:58
KoblerS
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #432
Related to #481
Problem
Clean attachments intermittently returned a 202/stuck-in-Scanning state on download, because the download-triggered re-scan in
rescan()(lib/generic-handlers.js) wrote the status toScanningin a non-awaitedcds.tx(...)before spawning the scan:The comment promised "commit before emitting", but the
cds.txis not awaited, so there is no happens-before guarantee. The spawned scan (_scanAttachmentsFile) also setsScanningas its first step and later writesClean. Under load the un-awaitedScanningcommit is starved on the DB connection pool and lands after the scan's Clean commit → last-writer-wins → row stuck in Scanning (visible in logs as Updated scan status toScanningfor undefined, since rescan passesreq.target.nameas a string).Fix
Remove the request-path Scanning write entirely (both the composition and inline-attachment branches), leaving only the cds.spawn that triggers the scan.
This is correct because the write was redundant, not load-bearing:
_scanAttachmentsFilealready sets the status to Scanning as its first committed step. Removing it:I reverted my earlier attempt (await cds.tx(...)). I first tried making the write safe by awaiting the
cds.tx(...). That fixed the ordering but made things worse in a different way: the awaited commit holds a DB connection across the 202 throw and collides with the detachedcds.spawnscan transaction. On a single-connection database (local SQLite dev server + test harness) this drained the pool (Pool is draining / database is not open) and hung the reques — reproducible on a UI-triggered rescan in local dev if you have additional things happening afterwards like audit log writes. Removing the write (rather than awaiting it) avoids both failure modes.Relationship to #442
Draft PR #442 takes the same removal approach. This PR arrives at the same conclusion independently, with the added data point that the await-the-tx alternative is not viable (pool drain on single-connection DBs). Happy to consolidate with #442 if you prefer that.
Out of scope
#481 (attachment stuck in Scanning after a crash between the Scanning and Clean writes) is a separate crash-recovery concern and is not addressed here.