Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: memory leak when reading chunks from a stream #16075

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DonIsaac
Copy link
Contributor

What does this PR do?

Fixes #12198

@robobun
Copy link

robobun commented Dec 31, 2024

Updated 10:08 PM PT - Dec 30th, 2024

@DonIsaac, your commit 31482ec has 6 failures in #8709:


🧪   try this PR locally:

bunx bun-pr 16075

.temporary => |*temporary| temporary.deinitWithAllocator(bun.default_allocator),
.temporary_and_done => |*temporary_and_done| temporary_and_done.deinitWithAllocator(bun.default_allocator),
else => {},
}
result.* = .{ .temporary = .{} };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause JSValues for .owned, etc. variants to point to leaked/undefined memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does line 1046 move or borrow?

Man I miss Rust's borrow checker...

@@ -1021,6 +1023,11 @@ pub const StreamResult = union(Tag) {
const value = result.toJS(globalThis);
value.ensureStillAlive();

switch (result.*) {
.temporary => |*temporary| temporary.deinitWithAllocator(bun.default_allocator),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temporary should mean that the StreamResult don't own the data and should be cloned, the owner (how created the StreamResult) should free it.

@Jarred-Sumner
Copy link
Collaborator

I'm skeptical this is either the cause or the fix.

More likely, we're not reporting the memory allocated in ArrayBufferSink to the GC, so it has no idea we allocated a bunch of memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Streams memory leak
4 participants