Skip to content

fix: prevent double-submit on upload and handle DB race on cdn insert#1535

Merged
SpikeViper merged 1 commit intoValour-Software:mainfrom
kuu-26:fix/upload-double-submit-and-db-race
Apr 18, 2026
Merged

fix: prevent double-submit on upload and handle DB race on cdn insert#1535
SpikeViper merged 1 commit intoValour-Software:mainfrom
kuu-26:fix/upload-double-submit-and-db-race

Conversation

@kuu-26
Copy link
Copy Markdown
Contributor

@kuu-26 kuu-26 commented Apr 18, 2026

Two related fixes for the upload flow:

1. Client: FileUploadComponent double-submit guard
The Upload button and Enter key had no guard against double-firing. Added _isUploading flag that blocks repeated clicks and disables the button during upload.

2. Server: CdnBucketService race condition handling
The check-then-insert pattern (AnyAsync → AddAsync → SaveChangesAsync) has a TOCTOU race under concurrent uploads. Both requests pass the AnyAsync check, both try to insert, one gets a DbUpdateException on the PK. The old code caught generic Exception and logged it as an error even though it was a harmless duplicate.

Changes:

  • Catch DbUpdateException specifically before the generic Exception handler
  • Detach the failed entity from the DbContext so it doesn't corrupt future operations
  • Only log as error if the row still doesn't exist after the race (genuinely unexpected)
  • Generic Exception catch remains as a safety net for actual failures

This should eliminate the Sentry alerts for VALOUR-BACKEND-2B (Failed DbCommand INSERT into cdn_bucket_items) while keeping the upload flow working correctly.

@kuu-26 kuu-26 requested a review from a team as a code owner April 18, 2026 16:26
@SigmaTel71
Copy link
Copy Markdown

For reference: fixes #1370.

@SpikeViper SpikeViper merged commit e2314d3 into Valour-Software:main Apr 18, 2026
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.

3 participants