Repository navigation
fix(billing): mount billing middleware once and acquire dev slots ato… - #1554
Open
devogechukwu wants to merge 1 commit into
Open
devogechukwu wants to merge 1 commit into
devogechukwu wants to merge 1 commit into
Conversation
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
Stops
/api/billing/portalfrom executing the billing middleware chain (billing rate limiter, REST limiter, per-developer concurrency middleware) twice by mounting the portal router inside the billing router before access log and timeout middleware. Replaces the check-then-acquire concurrency race condition with atomic synchronous slot acquisition.Closes #[issue-number]
Changes
src/routes/billing.ts: Mounted/portalusingcreateBillingPortalRouter()beforebillingAccessLogMiddlewareandcreateTimeoutMiddleware.src/routes/index.ts: Removed the redundant separate/billing/portalmount./api/billing/portal/*) and response shapes remain unchanged.src/utils/developerSemaphore.ts: AddedtryAcquire(developerId: string): (() => void) | nullto synchronously verify capacity/queue and incrementactiveCount. Returns an idempotent release function.src/middleware/perDevConcurrency.ts: ReplacedgetCurrentActiveSlotCountscomparison and deferredwithSlotwithconst release = semaphore.tryAcquire(userId). Fails fast with429on null and guards slot release onfinishandcloseso it releases exactly once.src/middleware/perDevConcurrency.test.tscoveringtryAcquire, idempotent double-release (finishfollowed byclose), and error recovery.src/routes/billing.portal.mount.test.tsto verify middleware chains execute exactly once on portal routes.docs/per-dev-concurrency.mdand verified route map alignment inARCHITECTURE.md.Limiter Invocation Counts
Closes #1503