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: fixes cases re throttledPromised: abort misbehaviour and not awaited queue #865

Closed
wants to merge 8 commits into from

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

@alvarosabu alvarosabu changed the title Fix 2 cases re throttledPromised: abort misbehaviour and not awaited queue fix: fixes cases re throttledPromised: abort misbehaviour and not awaited queue Nov 12, 2024
@alvarosabu alvarosabu self-assigned this Nov 12, 2024
@alvarosabu alvarosabu added the bugfix [PR] Fixes a bug label Nov 12, 2024
tsconfig.json Outdated Show resolved Hide resolved
Copy link

pkg-pr-new bot commented Nov 12, 2024

Open in Stackblitz

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

commit: 7289f85

@@ -15,7 +15,7 @@ type Queue = {

interface ISbThrottle {
abort: () => any
(args: []): Promise<Queue>
(...args: any): Promise<Queue>
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking: @alexjoverm Can we do anything to avoid using any here? I will leave it to your personal criteria if it's something we should do on the scope of this PR or in the v7 refactor. In normal cases I would block a PR from merging if there are any on the types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's do, will need some extra help as I think we can do this type a bit more precise

@alexjoverm
Copy link
Contributor Author

Moving it to #869 for difficulties renaming one of the commits

@alexjoverm alexjoverm closed this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix [PR] Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Storyblok client throttling crashing Astro adapter in CloudFlare Worker
2 participants