fix: race condition when importing AsyncLocalStorage#17350
Conversation
🦋 Changeset detectedLatest commit: 237fde0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
This still looks racey to me. Maybe it's not actually possible to have a race due to how this code is used that I don't have context for, but in isolation if |
|
Yeah, maybe this? /** @type {AsyncLocalStorage<RenderContext> | null} */
let als = null;
/** @type {Promise<void> | null} */
let als_promise = null;
export function init_render_context() {
als_promise ??= import('node:async_hooks')
.then((hooks) => {
als = new hooks.AsyncLocalStorage();
})
.catch(noop);
return als_promise;
} |
|
lol, one step ahead of you |
|
Can confirm this fixes the Astro test that was breaking. Thanks a lot! |
|
that somehow broke everything, brb |
Closes #17345 -- basically if you get the timings actually perfectly right it appears you get two copies of ALS, one which gets used for the first half of the first render and another that gets used for every subsequent render (including the second half of the first render, which causes the error). I have no idea how to test this other than running the reproduction in the original issue, which this fixes. (@florian-lefebvre, can you verify as well? Thanks!)
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint