Fix tile cache purge timeout on large caches#216
Merged
Conversation
Convert synchronous LRU/full cache purge to background operations with real-time SSE progress reporting. Return HTTP 202 Accepted immediately instead of blocking the request until completion. - Add atomic _purgeInProgress guard (Interlocked.CompareExchange) to prevent concurrent purge operations; return 409 Conflict - Broadcast progress via SSE (started/progress/completed/failed) - Reduce file-delete lock chunk size 100→10 with Task.Yield() to minimize CacheTileAsync writer starvation during purge - Admin UI: animated progress bar, on-load SSE reconnect, SSE retry on connection drop, disabled buttons during purge - Tile-provider-change purge respects concurrency guard
Owner
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
- Fix TOCTOU SSE gap: move "started" broadcast inside purge methods after CompareExchange guard, so losing concurrent requests never emit a dangling "started" event with no "completed"/"failed" - Fix DRY: replace duplicated GetCacheStatus/GetCacheStatusFromScope with shared BuildCacheStatusAsync(TileCacheService) helper - Fix SseService inconsistency: capture _sseService singleton before Task.Run instead of re-resolving from DI scope - Fix flaky test: PurgeLRUCacheAsync_RejectsSecondConcurrentPurge now uses DelayingSseService to keep purge in-flight reliably (SlowTileHandler doesn't help since LRU purge doesn't fetch tiles) - Fix inaccurate comment: _purgeInProgress doc now correctly states InvalidOperationException (not "409 Conflict" which is HTTP-layer)
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.
Summary
Closes #207
DeleteLruCacheandDeleteAllMapTileCacheadmin actions to backgroundTask.Runoperations, returning HTTP 202 Accepted immediately_purgeInProgressconcurrency guard (Interlocked.CompareExchange) — second purge request returns 409 Conflict; tile-provider-change auto-purge skips gracefullystarted/progress/completed/failedevents) onadmin-tile-cache-purgechannel_cacheLockfile-delete chunk size from 100 to 10 withTask.Yield()between chunks to minimizeCacheTileAsyncwriter starvation during large purgesInvalidOperationExceptioncaught silently without broadcasting misleading "failed" eventfinallyblock, even on mid-purge failure or early returnTest plan
PurgeAllCacheAsync_RejectsSecondConcurrentPurge— verifies only one purge runs, second throwsPurgeLRUCacheAsync_RejectsSecondConcurrentPurge— same for LRU variantPurgeAllCacheAsync_BroadcastsProgressViaSse— verifies SSE events are broadcast with correct channel and payload structurePurgeLRUCacheAsync_BroadcastsProgressViaSse— same for LRU variantPurgeAllCacheAsync_GuardIsReleasedAfterFailure— verifies_purgeInProgressresets after completion