[PR #12024] fix: prevent memory leaks from AbortController closures #14034

Closed
opened 2026-02-16 18:18:51 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12024

State: closed
Merged: Yes


What does this PR do?

Inspired by https://x.com/jarredsumner/status/2017825694731145388. Definitely not expecting to see the same 1 gb saving but its at least more correct.

Arrow functions like () => controller.abort() capture the entire lexical scope, including large request bodies. When attached to long-lived signals or timeouts, this memory cannot be reclaimed.

Using controller.abort.bind(controller) only retains a reference to the controller itself, allowing request bodies to be GC'd.

How did you verify your code works?

see (AI generated) abort-leak.test.ts. I am sure there's a better way to verify this fix, but I do not know what that way is.

related issues

There are tons of memory leak issues: https://github.com/anomalyco/opencode/issues/9385

Relates to: #9385

(It might not actually fix that particular issue. But the contributing bot makes me put that there)

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12024 **State:** closed **Merged:** Yes --- ### What does this PR do? Inspired by https://x.com/jarredsumner/status/2017825694731145388. Definitely not expecting to see the same 1 gb saving but its at least _more_ correct. Arrow functions like `() => controller.abort()` capture the entire lexical scope, including large request bodies. When attached to long-lived signals or timeouts, this memory cannot be reclaimed. Using `controller.abort.bind(controller)` only retains a reference to the controller itself, allowing request bodies to be GC'd. ### How did you verify your code works? see (AI generated) `abort-leak.test.ts`. I am sure there's a better way to verify this fix, but I do not know what that way is. ### related issues There are tons of memory leak issues: https://github.com/anomalyco/opencode/issues/9385 Relates to: #9385 (It might not actually fix that particular issue. But the contributing bot makes me put that there)
yindo added the pull-request label 2026-02-16 18:18:51 -05:00
yindo closed this issue 2026-02-16 18:18:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14034