Repository navigation
fix: encodeViaTurboStream leaked memory via unremoved AbortSignal listener - #14900
Conversation
…tener Co-Authored-By: Marvin Luchs <875017+luchsamapparat@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 86fdf73 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
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 |
|
Ok scratch that, after chatting in Discord about it I think something like this is the right approach: diff --git a/packages/react-router/lib/server-runtime/single-fetch.ts b/packages/react-router/lib/server-runtime/single-fetch.ts
index aecd30970..9f929fdc6 100644
--- a/packages/react-router/lib/server-runtime/single-fetch.ts
+++ b/packages/react-router/lib/server-runtime/single-fetch.ts
@@ -390,14 +390,18 @@ export function encodeViaTurboStream(
// through React's rendering stream before we call `abort()` on that. If the
// user provides their own it's up to them to decouple the aborting of the
// stream from the aborting of React's `renderToPipeableStream`
+ let clearStreamTimeout: (() => void) | undefined;
let timeoutId = setTimeout(
- () => controller.abort(new Error("Server Timeout")),
+ () => {
+ controller.abort(new Error("Server Timeout"));
+ clearStreamTimeout();
+ },
typeof streamTimeout === "number" ? streamTimeout : 4950,
);
- let clearStreamTimeout = () => clearTimeout(timeoutId);
+ clearStreamTimeout = () => clearTimeout(timeoutId);
- requestSignal.addEventListener("abort", clearStreamTimeout);
+ requestSignal.addEventListener("abort", clearStreamTimeout, { once: true });
return encode(data, {
signal: controller.signal, |
|
Note: I did not experience any leaks that required this change when I measured, so possibly this required some other conditions to happen. What I wanted to do with the original PR was to make it collectable immediately, instead of waiting 5 seconds and make it move to old space. Great improvement. |
|
🤖 Hello there, We just published version Thanks! |
|
🤖 Hello there, We just published version Thanks! |
See #14891