Skip to content

RUST-1779 Fix a memory leak in cleanup tracking #979

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

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

abr-egn
Copy link
Contributor

@abr-egn abr-egn commented Oct 23, 2023

RUST-1779

There turned out to be two issues:

  • a straightforward bug where if a command generating a cleanup item finished quickly, that (inert) cleanup item was never removed from the list
  • incrementing an id to generate a hashmap key is basically pessimal behavior for hashmaps

To fix the second I switched the storage over to a vec with a secondary list of free indices for efficient removal. The generation tag ensures that a given Id won't remove a value that's re-used that slot in the vec. While the storage vec is never shrunk, the reuse of indices means it'll only grow up to capacity for peak concurrent cleanup operation execution.

@abr-egn
Copy link
Contributor Author

abr-egn commented Oct 23, 2023

Note: both evergreen failures are unrelated, it looks like ahash (used by bson) has started pulling in zerocopy v0.7.11, which fails both the MSRV and cargo-deny checks. I've filed https://jira.mongodb.org/browse/RUST-1780 to track that.

@abr-egn
Copy link
Contributor Author

abr-egn commented Oct 24, 2023

To fix the second I switched the storage over to a vec with a secondary list of free indices for efficient removal. The generation tag ensures that a given Id won't remove a value that's re-used that slot in the vec. While the storage vec is never shrunk, the reuse of indices means it'll only grow up to capacity for peak concurrent cleanup operation execution.

It turns out this is implemented by the slotmap crate; since the implementation in there is pretty simple, I'm inclined to leave it as-is instead of picking up another dependency.

@abr-egn abr-egn merged commit 897843b into mongodb:main Oct 26, 2023
abr-egn added a commit to abr-egn/mongo-rust-driver that referenced this pull request Nov 1, 2023
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 this pull request may close these issues.

2 participants