vitest-plugin: a Durable Object aborted during a dynamic import makes later imports of that module hang
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, typescript, vite
Research direction
Start with the reproduction in test/hang.test.ts and run npx vitest run to confirm the second test hangs after the Durable Object aborts during import("./lazy"). Then trace the module runner's cachedModule handling of concurrentModuleNodePromises, which the issue identifies as the suspected cause. Done means later imports of the same module settle after an abort, while the control test still passes.
Written by the indexing model from the issue text.
Description
What versions & operating system are you using?
@cloudflare/vitest-plugin 1.4.11, vitest 4.1.12, wrangler 4.156.0. Seen on macOS and on Linux.
Please provide a link to a minimal reproduction
The whole reproduction is below, in place of a link. It has a control test, and it fails the same way on each run.
wrangler.jsonc
{
"name": "repro",
"main": "src/index.ts",
"compatibility_date": "2026-10-01",
"compatibility_flags": ["nodejs_compat"],
"durable_objects": { "bindings": [{ "name": "VICTIM", "class_name": "Victim" }] },
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["Victim"] }]
}
vitest.config.ts
import { cloudflareTest } from "@cloudflare/vitest-plugin";
import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [cloudflareTest({ wrangler: { configPath: "./wrangler.jsonc" } })],
});
src/lazy.ts
export const value = 1;
src/index.ts
import { DurableObject } from "cloudflare:workers";
export class Victim extends DurableObject {
importAndAbort(abort: boolean) {
void import("./lazy");
if (abort) this.ctx.abort("stopped during an import");
}
}
export default { fetch: () => new Response("ok") };
test/hang.test.ts
import { env } from "cloudflare:test";
import { expect, it } from "vitest";
const importLazy = () =>
Promise.race([
import("../src/lazy").then(() => "loaded"),
scheduler.wait(3_000).then(() => "hung"),
]);
it("control: no abort", async () => {
await env.VICTIM.getByName("a").importAndAbort(false);
await scheduler.wait(200);
expect(await importLazy()).toBe("loaded");
});
it("abort during an import", async () => {
await env.VICTIM.getByName("b").importAndAbort(true).catch(() => {});
expect(await importLazy()).toBe("loaded");
}, 10_000);
Run npx vitest run. The control passes. The second test fails with expected 'hung' to be 'loaded'.
Describe the Bug
If ctx.abort() stops a Durable Object while a dynamic import() is in progress, each later import of that module in the same test file waits forever, also from the test itself.
The cause seems to be in Vite's module runner. ModuleRunner.cachedModule keeps each import in progress in concurrentModuleNodePromises, and removes the entry in a .finally(). It asks for the module through the transport on each import, also when the module has run already. When the Durable Object is aborted, the entry stays in the map, and later imports of that URL wait for a promise that does not settle.
This is hard to find, because it shows up as a timeout in tests that come later, and only when the abort falls inside the import. A library that imports modules lazily on each call makes this more likely: convex-test does this.
The expected behaviour is that an abort does not affect imports made by other contexts.
A workaround is to keep each module after its first load, so that later calls do not import. An abort during the first import of a module can still cause the hang.
Please provide any relevant error logs
There is no error. The later import does not settle.
- Dominant language
- TypeScript
- Stars
- 4.7k
- Forks
- 1.7k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 282
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
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.
More from cloudflare/workers-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
cloudflare/workers-sdk#17215 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
cloudflare/workers-sdk#17189 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cloudflare/workers-sdk#17187 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
cloudflare/workers-sdk#17175 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/workers-sdk#17174 ·
Maintainers usually reply within 1 day
All issues in cloudflare/workers-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
earendil-works/pi#12615 ·
Maintainers usually reply within 1 day
-
My Caps shows "Shared" on private Caps that were never sharedPossibly taken @AksharP5 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CapSoftware/Cap#4569 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OHDSI/Data2Evidence#3749 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
Maintainers usually reply within 2 days