Fix malware scan status stuck at Scanning after draft activation by Schmarvinius · Pull Request #771 · cap-java/cds-feature-attachments · GitHub
Skip to content

Fix malware scan status stuck at Scanning after draft activation#771

Merged
Schmarvinius merged 4 commits into
mainfrom
bugfix/scanner-not-updating-active-entity
Mar 31, 2026
Merged

Fix malware scan status stuck at Scanning after draft activation#771
Schmarvinius merged 4 commits into
mainfrom
bugfix/scanner-not-updating-active-entity

Conversation

@Schmarvinius

@Schmarvinius Schmarvinius commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a race condition where activating a draft before the async malware scan completes causes the attachment to stay at status: Scanning forever
  • The async scanner now updates both draft and active entities after scanning, so the result is persisted regardless of which table the row lives in at update time
  • Also fixes duplicate scanning: previously the same file was scanned twice for draft-enabled entities, now it is scanned once

Closes #770

Root Cause

scanAttachment() selected the attachment row before the scan, then updated the same entity after the scan. If the draft was activated during the scan, the draft row was deleted and the update hit 0 rows. The active entity was skipped because it had 0 rows at select time.

Fix

Split scanAttachment() into two phases:

  1. Find the first entity with the attachment and scan its content
  2. Update all candidate entities (both draft and active) with the scan result

An UPDATE against a table with no matching row is a harmless 0-row no-op. The table that has the row gets updated.

@hyperspace-insights

Copy link
Copy Markdown
Contributor

@hyperspace-insights hyperspace-insights Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces a two-phase scan-then-update-all-entities approach to fix a real race condition, but has several substantive correctness issues: the unconditional "update all" loop can stamp unrelated attachments that appear between SELECT and UPDATE; findAndScanAttachment relies on re-reading an already-iterated Result object whose re-readability is untested; and a test's name/assertions directly contradict its intent, obscuring the actual behaviour under review.

PR Bot Information

Version: 1.19.9 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • File Content Strategy: Full file content
  • Correlation ID: d3dddd80-2c4e-11f1-9772-da3e87f9e8b3
  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.6-sonnet

@Schmarvinius Schmarvinius requested a review from a team March 31, 2026 07:30

@lisajulia lisajulia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Schmarvinius Schmarvinius enabled auto-merge (squash) March 31, 2026 09:33
@Schmarvinius Schmarvinius merged commit edc3c7d into main Mar 31, 2026
12 checks passed
@Schmarvinius Schmarvinius deleted the bugfix/scanner-not-updating-active-entity branch March 31, 2026 09:56
@Schmarvinius Schmarvinius mentioned this pull request Mar 31, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malware scan status stuck at 'Scanning' when draft is activated before async scan completes

2 participants