Fix prefetch race condition, transaction observable leak, and media store getUrl crash#3396
Merged
Fix prefetch race condition, transaction observable leak, and media store getUrl crash#3396
Conversation
…d media store crash - Replace Promise.all with sequential for...of in DiaBackendAssetPrefetchingService.prefetch() to eliminate concurrent writes to the shared currentCount variable - Add catchError(EMPTY) to the downloadExpired$ observable chain in DiaBackendTransactionRepository to prevent hanging subscriptions on failure - Wrap MediaStore.getUrl() in try-catch to return empty string gracefully instead of silently crashing the display pipeline Agent-Logs-Url: https://github.com/numbersprotocol/capture-cam/sessions/ff0c4f0b-d6a2-43f0-8f11-98535fdf9f3f Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix concurrency bugs in prefetching service
Fix prefetch race condition, transaction observable leak, and media store getUrl crash
Apr 2, 2026
Replace fully sequential for...of with batched Promise.all (batch size 5). Avoids the original 100-concurrent-request race condition while preventing the ~10x slowdown of fully sequential processing. 100 assets: ~4-8s (batched) vs ~20s (sequential) vs ~2-5s (unbounded)
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.
Three concurrency and error-handling bugs in core shared services causing non-deterministic progress reporting, potential observable memory leaks, and silent media display failures.
Changes
Prefetch race condition (
dia-backend-asset-prefetching.service.ts): ReplacePromise.all+ concurrent.mapwith a sequentialfor...ofloop. Concurrent async callbacks were racing on the sharedcurrentCountvariable, causing skipped or out-of-order progress callbacks.Transaction observable leak (
dia-backend-transaction-repository.service.ts): AddcatchErrorreturningEMPTYat the end of thedownloadExpired$pipeline. A failure anywhere in theconcatMapchain previously terminated the observable uncleanly, leaving subscribers hanging. ImportsEMPTYandcatchErrorfromrxjs.Media store
getUrlcrash (media-store.service.ts): WrapgetUrl()body intry/catch. Failures fromCapacitor.convertFileSrc(),getUri(), orreadWithFileSystem()were propagating as unhandled rejections and silently breaking the display pipeline. Now logs the error and returns''as a graceful fallback.