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

reserve_inner over allocates which can lead to a OOM conidition #559

Closed
schultetwin1 opened this issue Jul 29, 2022 · 0 comments · Fixed by #560
Closed

reserve_inner over allocates which can lead to a OOM conidition #559

schultetwin1 opened this issue Jul 29, 2022 · 0 comments · Fixed by #560

Comments

@schultetwin1
Copy link
Contributor

Summary

reseve_inner will double the size of the underlying shared vector instead of just extending the BytesMut buffer in place if a call to BytesMut::reserve would fit inside the current allocated shared buffer. If this happens repeatedly you will eventually attempt to allocate a buffer that is too large.

Repro

fn reserve_in_arc_unique_does_not_overallocate_after_split() {
    let mut bytes = BytesMut::from(LONG);
    let orig_capacity = bytes.capacity();
    drop(bytes.split_off(LONG.len() / 2));
    let new_capacity = bytes.capacity();
    bytes.reserve(orig_capacity - new_capacity);
    assert_eq!(bytes.capacity(), orig_capacity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant