You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
setInterval(()=>{Bun.gc(true);},100);constp=Bun.spawn(['cat'],{stdin: 'pipe',stdout: 'pipe',})constr=p.stdout.getReader()while(true){constbuf=newUint8Array(1_000_000);awaitp.stdin.write(buf);leti=0;while(true){const{ value }=awaitr.read();i+=value?.length??0;if(i>=buf.length){break;}}}
What is the expected behavior?
Each iteration just wait until the buffer is streamed through cat, so I'd expect memory not to increase.
What do you see instead?
CPU 100%, memory increases rapidly.
Interestingly enough, when every byte has been streamed, if I add another .read() (which rightfuly returns no data), the memory leak disapears:
setInterval(()=>{Bun.gc(true);},100);constp=Bun.spawn(['cat'],{stdin: 'pipe',stdout: 'pipe',})constr=p.stdout.getReader()while(true){constbuf=newUint8Array(1_000_000);awaitp.stdin.write(buf);leti=0;while(true){const{ value }=awaitr.read();i+=value?.length??0;if(i>=buf.length){// 👉 this fixes the leak ! (and never throws)const{value: value2}=awaitr.read();if(value2?.length){thrownewError('Expected EOF');}break;}}}
Additional information
This issue is kind of linked to #12194 (which I discovered investigating this leak)
The text was updated successfully, but these errors were encountered:
When called on a .temporary result, StreamResult.toJS allocates a new buffer and copies the data over. The original ByteList is then never de-allocated.
What version of Bun is running?
1.1.17+bb66bba1b
What platform is your computer?
Darwin 23.1.0 arm64 arm
What steps can reproduce the bug?
Execute the below code, and watch memory usage:
What is the expected behavior?
Each iteration just wait until the buffer is streamed through
cat
, so I'd expect memory not to increase.What do you see instead?
CPU 100%, memory increases rapidly.
Interestingly enough, when every byte has been streamed, if I add another
.read()
(which rightfuly returns no data), the memory leak disapears:Additional information
This issue is kind of linked to #12194 (which I discovered investigating this leak)
The text was updated successfully, but these errors were encountered: