Repository navigation
Conversation
Adds src/middleware/idempotency.ts — a Redis-backed idempotency middleware that prevents duplicate processing of mutating requests. The core fix for FaveTeamz#1013: the in-flight lock key (idem:lock:<key>) is now deleted inside a try...finally block, so any unhandled exception thrown by a downstream route handler triggers immediate lock release instead of letting the key persist until TTL expiry. This allows clients to retry safely after an unexpected server error. Key behaviours implemented: - Missing Idempotency-Key on mutating requests → 400 - Completed result found in Redis → 409-free replay with original status/body - Duplicate in-flight request → 409 duplicate_request - Successful response persisted for 24 h under idem:result:<key> - Lock always released in finally block (fixes FaveTeamz#1013) Wires idempotencyMiddleware into app.ts after the audit middleware so it applies globally to all POST/PUT/PATCH/DELETE routes. Closes FaveTeamz#1013
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.
What was implemented
Adds
src/middleware/idempotency.ts— a Redis-backed idempotency middleware that prevents duplicate processing of mutating HTTP requests (POST,PUT,PATCH,DELETE).Core fix (#1013)
The in-flight lock key (
idem:lock:<key>) is now deleted inside atry...finallyblock. Previously, if a downstream route handler threw an unexpected error, the lock would persist in Redis until its TTL expired — blocking clients from safely retrying. With thefinallyblock, the lock is always released immediately, regardless of whether the handler succeeded or threw.Behaviour overview
Idempotency-Keyheader on mutating requestmissing_idempotency_keyX-Idempotency-Replayed: trueduplicate_requestidem:result:<key>finallyblock — client can retryFiles changed
src/middleware/idempotency.ts— new middleware (try…finally lock cleanup)src/app.ts— wiresidempotencyMiddlewarein after audit middlewareCloses #1013