Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loose-humans-join.md
Comment thread
petebacondarwin marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/vite-plugin": patch
---

Fix potential memory leak in module runner
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ async function runInRunnerObject(
const id = nextCallbackId++;
pendingCallbacks.set(id, callback);

const stub = env.__VITE_RUNNER_OBJECT__.get("singleton");
await stub.executeCallback(id);
try {
const stub = env.__VITE_RUNNER_OBJECT__.get("singleton");
await stub.executeCallback(id);

const result = callbackResults.get(id);
callbackResults.delete(id);

return result;
return callbackResults.get(id);
} finally {
pendingCallbacks.delete(id);
callbackResults.delete(id);
}
}

/**
Expand Down Expand Up @@ -152,7 +154,6 @@ export class __VITE_RUNNER_OBJECT__ extends DurableObject<WrapperEnv> {
*/
async executeCallback(id: number): Promise<void> {
const callback = pendingCallbacks.get(id);
pendingCallbacks.delete(id);

if (!callback) {
throw new Error(`No pending callback with id ${id}`);
Expand Down
Loading