Skip to content

fix: handle corrupted Redis cache entries as cache misses (#736) - #800

Merged
nonsobethel0-dev merged 1 commit into
Parashield-Protocol:mainfrom
daniella-techie:fix/735-736-737-738-redis-cache-json-parse
Oct 19, 2026
Merged

nonsobethel0-dev merged 1 commit into
Parashield-Protocol:mainfrom
daniella-techie:fix/735-736-737-738-redis-cache-json-parse

Conversation

@daniella-techie

Copy link
Copy Markdown
Contributor

Summary

Fixes how the Redis-backed idempotency response cache (src/common/middleware/idempotency.middleware.ts) handles corrupted entries.

Before this change, a corrupted entry was skipped but never removed. An entry that parsed as JSON but had the wrong shape (for example null, a missing body, or an invalid status) could also make the replay fail after headers had already been written.

Changes

  • Catch JSON parse errors: parsing now happens in its own parseCachedEntry helper, and its result is checked before use: it must be an object with a body and an integer HTTP status from 100 to 599.
  • Treat as a cache miss: an invalid entry returns false from replayCached, so the request goes through the normal lock-and-handle flow.
  • Delete corrupted entries: the bad key is removed with DEL. If the delete itself fails, a warning is logged and the request still goes ahead. The handler's fresh 2xx response then replaces the entry.
  • Tests: new cases cover invalid JSON, null, a missing body, a non-numeric status and an out-of-range status, plus a failing DEL.

Test plan

  • npx jest src/common/middleware/idempotency.middleware.spec.ts: 10/10 passing

Closes #735
Closes #736
Closes #737
Closes #738

@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@daniella-techie Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nonsobethel0-dev
nonsobethel0-dev merged commit 0095a29 into Parashield-Protocol:main Oct 19, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants