`kv.scanIterator()` not terminating in `for await` loop after updating to version 2.0.0
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 595
- Forks
- 101
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 1
Description
After updating from version 1.0.1 to version 2.0.0, the function kv.scanIterator() no longer works correctly. When using it in a for await loop, the loop never exits. It is not an infinite loop as it processes keys correctly, but it never reaches the return statement of the function.
Here is the code demonstrating the issue:
export async function startRun() {
console.log("Iniciando for");
for await (const key of kv.scanIterator()) {
const value = await kv.get(key);
console.log({ key, value });
console.log("ultima iteración del for");
}
return "Finalizando y retornando";
}
The console.log statements execute correctly for each key found, but the loop never terminates, preventing the function from returning.
I attempted to resolve the issue by adding the following configuration:
const kv = createClient({
url: process.env.KV_REST_API_URL,
token: process.env.KV_REST_API_TOKEN,
enableAutoPipelining: false,
});
However, the problem persists. As a temporary workaround, I have reverted to version 1.0.1, where the function works as expected.
Steps to Reproduce:
- Update
@vercel/kvfrom version 1.0.1 to version 2.0.0. - Use
kv.scanIterator()in afor awaitloop. - Observe that the loop never exits.
Expected Behavior:
The for await loop should terminate after processing all keys and the function should return the expected result.
Actual Behavior:
The for await loop processes keys correctly but never exits, preventing the function from returning.
Environment:
@vercel/kvversion: 2.0.0- Node.js version: 20.15.0
- Operating System: Windows 11
Thank you for your assistance in resolving this issue.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with @vercel/kv 2.0.0 using the provided startRun function and compare its scanIterator behavior with version 1.0.1. Trace the iterator's termination path; done means the for-await loop processes all keys, exits, and reaches the return statement without requiring auto-pipelining to be disabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100