Repository navigation
fix: two high-severity host crashes (#232 AuditMiddleware DbContext race, #223 RateLimiting missing table) - #241
Closed
antosubash wants to merge 2 commits into
Closed
antosubash wants to merge 2 commits into
antosubash wants to merge 2 commits into
Conversation
…ace (#232) AuditMiddleware fanned out five GetSettingAsync calls via Task.WhenAll on every request. ISettingsContracts is scoped over a single SettingsDbContext, so on a cold FusionCache entry the concurrent queries raced the context ("A second operation was started on this context instance"), which the global exception handler turned into intermittent HTTP 500s on the first hit after startup. Await the five lookups sequentially instead. Adds a regression test that fails if the middleware ever invokes the scoped settings service concurrently.
…sh (#223) RateLimitRuleCache is an IHostedService that queries RateLimiting_Rules in StartAsync. If the table doesn't exist — e.g. EnsureCreated() ran on an existing dev database before RateLimiting was added, or migrations weren't applied — the unhandled provider exception crashed the entire host before it could start listening. Catch DbException in RefreshAsync, log a warning, and keep the current (empty at startup) snapshot so the host starts and degrades gracefully with no DB-defined rules. Adds a regression test covering the missing-table path.
Deploying simplemodule-website with
|
| Latest commit: |
8f47048
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a2258a79.simplemodule-website.pages.dev |
| Branch Preview URL: | https://claude-github-issues-ap2fc.simplemodule-website.pages.dev |
antosubash
marked this pull request as ready for review
June 4, 2026 19:53
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
Fixes two independent, high-severity runtime crashes.
#232 — AuditMiddleware races SettingsDbContext → intermittent 500s
AuditMiddlewareran on every request and fanned out fiveISettingsContracts.GetSettingAsync(...)calls viaTask.WhenAll.ISettingsContractsis scoped over a singleSettingsDbContext, and on a cold FusionCache entry each call queries it — so the concurrent queries raced the context (A second operation was started on this context instance...), surfacing as intermittent HTTP 500s on the first hit after startup (reliably reproduced under concurrent browser/asset requests).Fix: await the five lookups sequentially instead. The composite FusionCache entry still means this only runs on a cache miss (~once/60s), so there's no meaningful latency change.
#223 — RateLimitRuleCache crashes the host when
RateLimiting_Rulesis missingRateLimitRuleCacheis anIHostedServicethat queriesRateLimiting_RulesinStartAsync. If the table doesn't exist — e.g.EnsureCreated()ran on an existing dev DB before RateLimiting was added, or migrations weren't applied — the unhandled provider exception crashed the entire host before it started listening.Fix: catch
DbException(provider-agnostic) inRefreshAsync, log a warning, and keep the current (empty at startup) snapshot so the host starts and degrades gracefully with no DB-defined rules.Tests
Task.WhenAll). 10/10 pass.RefreshAsyncagainst a context whose table was never created and asserts no throw. 8/8 pass.Notes
Both fixes are minimal and independent — reviewable per-commit:
fix(auditlogs): load audit settings sequentially to avoid DbContext race (#232)fix(ratelimiting): tolerate missing RateLimiting_Rules table on refresh (#223)Closes #232
Closes #223
Generated by Claude Code