Skip to content

fix(MUF-11810): treat a record missing on get as a cache miss - #56

Open
corradopetrelli wants to merge 1 commit into
mainfrom
fix/MUF-11810-cache-get-race
Open

corradopetrelli wants to merge 1 commit into
mainfrom
fix/MUF-11810-cache-get-race

Conversation

@corradopetrelli

Copy link
Copy Markdown

Summary

getDataCacheRecord (src/internal.ts) called cache.has(key) and then cache.get(key). If the key expired or was deleted by a concurrent invalidation between the two calls, get returned undefined and the destructuring threw:

TypeError: Cannot destructure property 'result' of '(intermediate value)' as it is undefined

This happened in production in refunds (syncUser, 2026-10-26 06:17 UTC) with @jointlytech/cache-candidate-kv-adapter on Redis.

Change

  • The record is now read with a single cache.get(key), and has is no longer called on the read path. That also saves one adapter round-trip per lookup.
  • A missing record (undefined, or null from an adapter that returns it) is handled as a cache miss, so the wrapped function runs.
  • Behaviour for valid and expired records is unchanged.

Tests

  • New regression test should treat a record vanished between has and get as a cache miss: an adapter whose has returns true and whose get returns undefined. The test checks that the function runs, that its result is returned and that onCacheHit is not fired.
  • On the pre-fix code it fails with the production error. With the fix, npm test reports 24 passing and 0 failing. npm run lint and the prettier check also pass.

Follow-up

Releasing a new version and bumping it in refunds is handled in a separate cycle.

🤖 Generated with Claude Code

getDataCacheRecord called cache.has() and then cache.get(): if the key
expired or was invalidated in between, get() returned undefined and the
destructuring threw "Cannot destructure property 'result'". It now reads
the record with a single get() and treats a missing record as a miss.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@snyk-io

snyk-io Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants