Skip to content

fix: bound key SCAN by type filter to stop infinite loop#58

Open
ytkimirti wants to merge 1 commit into
masterfrom
DX-2789-fix-scan-type-filter-loop
Open

fix: bound key SCAN by type filter to stop infinite loop#58
ytkimirti wants to merge 1 commit into
masterfrom
DX-2789-fix-scan-type-filter-loop

Conversation

@ytkimirti

Copy link
Copy Markdown
Collaborator

Problem

Filtering keys by a type that's sparse or absent in the db (e.g. set/list on a hash-heavy database) made the key list scan loop forever. scanUntilAvailable kept issuing SCAN ... TYPE <x> until it found a match or walked the entire keyspace — on a 45M-key db that's tens of thousands of requests hammering Redis with no visible result. Raising COUNT can't help: Upstash REST caps SCAN at ~1000 keys/call regardless of COUNT (measured). Switching the filter mid-scan also didn't cancel the in-flight loop, so it kept fetching in the background.

Fix

  • Cap SCAN round-trips per fetch (MAX_SCANS_PER_FETCH). When the budget is spent with no match, pause and show a Keep scanning action instead of looping.
  • Thread React Query's abort signal into the scan loop so changing the filter/type cancels it immediately.
  • Raise the COUNT ceiling to the 1000 server cap (was 500).

Closes DX-2789

Filtering keys by a sparse or absent type (e.g. set/list on a hash-heavy
db) made scanUntilAvailable walk the entire keyspace looking for a match —
effectively an infinite loop that hammers the db. Upstash REST also caps
SCAN at ~1000 keys/call, so raising COUNT can't fix it.

- Cap SCAN round-trips per fetch (MAX_SCANS_PER_FETCH); pause and let the
  user resume via a "Keep scanning" action instead of looping.
- Thread React Query's abort signal so changing the filter cancels the
  in-flight scan instead of fetching in the background.
- Raise the COUNT ceiling to the 1000 server cap.
@linear-code

linear-code Bot commented Jun 24, 2026

Copy link
Copy Markdown

DX-2789

@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-redis-browser Ready Ready Preview, Comment Jun 24, 2026 1:39pm

Request Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant