-
-
Notifications
You must be signed in to change notification settings - Fork 113
Fix Memory leaks and add tests to prevent memory leaks during md_clear from passing #1233
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
+92
−2
Merged
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
633e9e8
add test for memory leakage during deletion of value
Vizonex 8acea81
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c06df7d
trim memory before checking if memory had been leaked to prevent boug…
Vizonex 22c7d92
trim ram in multidict_pop.py when testing item deletion so that bougu…
Vizonex a1fe938
add contribution to timeline
Vizonex 4ec1158
merge the two functions together so that mypy will accept it.
Vizonex 2bf1cb7
typo fix
Vizonex 45f4066
see if this works...
Vizonex 7843457
revert
Vizonex 9712cfe
Fixed Memory Leak with deleting and adding values
Vizonex 9fa0bfc
fix crashing and ensure multidicts can actually clear entries
Vizonex 1059ec8
remove malloc-trim there is not need for it here
Vizonex 9f2903c
_md_refdump is not version compatable so I'll comment it out for now...
Vizonex ecb03e7
increase timeout so that workflow doesn't cut off
Vizonex fac4442
increase fault handler timeout so that debug versions can finish in time
Vizonex bd37797
revert this was the worng timeout
Vizonex 4e67d13
lessen amount of time memory leak takes to test
Vizonex c500173
higher amount but print how big it was so we know where it should be …
Vizonex ad1be49
make sure code-coverage does its job and fix up md_clear so that all …
Vizonex e374329
label that we bugfixed a problem
Vizonex e1c5f14
cleanup debug artifacts
Vizonex fb25e16
Apply suggestions from code review
asvetlov 0ccaf30
Apply suggestions from code review
asvetlov 232806b
Apply suggestions from code review
asvetlov 3a08bfc
Update multidict/_multilib/hashtable.h
asvetlov 53b7bb6
Update multidict/_multilib/hashtable.h
asvetlov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix ``MutliDict`` & ``CIMultiDict`` memory leak when deleting values or clearing them | ||
| -- by :user:`Vizonex` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Added memory leak test for popping or deleting attributes from a multidict to prevent future issues or bogus claims. | ||
| -- by :user:`Vizonex` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ objgraph==3.6.2 | |
| pytest==8.4.0 | ||
| pytest-codspeed==3.2.0 | ||
| pytest-cov==6.1.0 | ||
| psutil==7.0.0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Test for memory leaks surrounding deletion of values or | ||
| # bad cleanups. | ||
| # SEE: https://github.com/aio-libs/multidict/issues/1232 | ||
| # We want to make sure that bad predictions or bougus claims | ||
| # of memory leaks can be prevented in the future. | ||
|
|
||
| import gc | ||
| import psutil | ||
| import os | ||
| from multidict import MultiDict | ||
|
|
||
|
|
||
| def trim_ram() -> None: | ||
| """Forces python garbage collection.""" | ||
| gc.collect() | ||
|
|
||
|
|
||
| process = psutil.Process(os.getpid()) | ||
|
|
||
|
|
||
| def get_memory_usage() -> int: | ||
| memory_info = process.memory_info() | ||
| return memory_info.rss / (1024 * 1024) # type: ignore[no-any-return] | ||
|
|
||
|
|
||
| keys = [f"X-Any-{i}" for i in range(100)] | ||
| headers = {key: key * 2 for key in keys} | ||
|
|
||
|
|
||
| def check_for_leak() -> None: | ||
| trim_ram() | ||
| usage = get_memory_usage() | ||
| assert usage < 50, f"Memory leaked at: {usage} MB" | ||
|
|
||
|
|
||
| def _test_pop() -> None: | ||
| for _ in range(10): | ||
| for _ in range(100): | ||
| result = MultiDict(headers) | ||
| for k in keys: | ||
| result.pop(k) | ||
| check_for_leak() | ||
|
|
||
|
|
||
| def _test_popall() -> None: | ||
| for _ in range(10): | ||
| for _ in range(100): | ||
| result = MultiDict(headers) | ||
| for k in keys: | ||
| result.popall(k) | ||
| check_for_leak() | ||
|
|
||
|
|
||
| def _test_popone() -> None: | ||
| for _ in range(10): | ||
| for _ in range(100): | ||
| result = MultiDict(headers) | ||
| for k in keys: | ||
| result.popone(k) | ||
| check_for_leak() | ||
|
|
||
|
|
||
| def _test_del() -> None: | ||
| for _ in range(10): | ||
| for _ in range(100): | ||
| result = MultiDict(headers) | ||
| for k in keys: | ||
| del result[k] | ||
| check_for_leak() | ||
|
|
||
|
|
||
| def _run_isolated_case() -> None: | ||
| _test_pop() | ||
| _test_popall() | ||
| _test_popone() | ||
| _test_del() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| _run_isolated_case() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.