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

fix: update throttle #869

Merged
merged 2 commits into from
Nov 19, 2024
Merged

fix: update throttle #869

merged 2 commits into from
Nov 19, 2024

Conversation

alexjoverm
Copy link
Contributor

We've been reported in #682, and thanks to the discovery of @dojscart in withastro/adapters#43 (comment) (really really thanks 🙏 ) we've managed to identify that the internal queue of the throttle promise wasn't being awaited properly, causing some edge cases to fail (like Cloudflare, and likely the SSG generation).

On the way, I also managed to find another case -> after aborting the queue, promises kept being added and got stuck in the queue unresolved forever.

Solution
Basically, now the promises in the queue are awaited properly after crossing the limit, and no new promises are getting added after aborting the queue.

Fixes #682

How to test the issue
Run the new test npx vitest run src/throttlePromise.test.ts against the src/throttlePromise.ts living in the main branch -> both test cases should fail
Now, run again the same test against the updated src/throttlePromise.ts from this branch -> both test cases should pass correctly
Aside from that, I can recommend to try to break the expected functionality of the throttlePromise and its internal queue. I tried via a local script to heavily load the queue with all kind of scenarios - thousands of calls, randomly make them fail, etc - and so far it worked out, but extra eyes and hands are always great.

Copy link

Fix the throttled issue

src/index.ts Outdated Show resolved Hide resolved
src/throttlePromise.ts Outdated Show resolved Hide resolved
Copy link

pkg-pr-new bot commented Nov 19, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/storyblok-js-client@869

commit: 1b83ebb

Copy link
Contributor

@edodusi edodusi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good to me 👍

@alexjoverm alexjoverm merged commit 59be18a into main Nov 19, 2024
6 checks passed
@alexjoverm alexjoverm deleted the fix/PRO-803-throttle-fix branch November 19, 2024 11:13
Copy link

🎉 This PR is included in version 6.10.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Storyblok client throttling crashing Astro adapter in CloudFlare Worker
2 participants