Closed silence-coding closed 1 year ago
After stream.remove, if an empty frame is stuffed into the buffer, it will not be removed later. https://github.com/hyperium/h2/blob/294000c0745c64009151a1ab39978cd6f02dfd68/src/proto/streams/counts.rs#L165-L167 https://github.com/hyperium/h2/blob/294000c0745c64009151a1ab39978cd6f02dfd68/src/proto/streams/recv.rs#L612
This is because stream.pending_recv.push_back(&mut self.buffer, event);
is executed first, and then streams are removed from transition_after
.
https://github.com/hyperium/h2/blob/294000c0745c64009151a1ab39978cd6f02dfd68/src/proto/streams/counts.rs#L119-L132
Can we solve this problem as simple as this?
if stream.is_released() {
return Ok(());
}
// Push the frame onto the recv buffer
stream.pending_recv.push_back(&mut self.buffer, event);
Thank you for investigating so thoroughly!
Can we solve this problem as simple as this?
Possibly. If you try that change, does the test suite still pass? Does your example show buffer count cleaning up?
is_released
In some scenarios, is_released is not true because the write-back response requires a stream.
The best way would be to check whether there is a residual pending_recv at stream.remove(), but this change is too much. I chose another way: discard data when no RecvStream exists.
@seanmonstar cloud you release a new version to fix this issue?
v0.3.16 is out today :)
v0.3.16 is out today :)
Which version does the memory leak problem come from? Does h2-0.2.4 Have this memory leak problem?
Does the memory have residual memory? https://github.com/hyperium/h2/blob/294000c0745c64009151a1ab39978cd6f02dfd68/src/proto/streams/recv.rs#L612
Currently, the count_buf method has been used to find that self.buffer has accumulated data.
When the client has only one request sent per second, the self.buffer count is still not released.![image](https://user-images.githubusercontent.com/32766901/203797186-2db1dc0c-9101-4c68-8863-c8552c32bf19.png)
Scenarios: client:
server:
For the crate of bytes, even if there is only one empty Bytes reference, the corresponding shared memory is not released.![image](https://user-images.githubusercontent.com/32766901/203795852-190b09b5-4bf6-4deb-8154-236bb7f896ea.png)