Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv.scanIterator() not terminating in for await loop after updating to version 2.0.0 #706

Open
UAHector opened this issue Jun 26, 2024 · 1 comment

Comments

@UAHector
Copy link

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:

  1. Update @vercel/kv from version 1.0.1 to version 2.0.0.
  2. Use kv.scanIterator() in a for await loop.
  3. 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/kv version: 2.0.0
  • Node.js version: 20.15.0
  • Operating System: Windows 11

Thank you for your assistance in resolving this issue.


@matzkoh
Copy link

matzkoh commented Sep 9, 2024

The same applies to kv.sscanIterator()

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

No branches or pull requests

2 participants