Conversation
The task header wasn't being dropped when the task was being destroyed.
Verified that the test passes and also that valgrind no longer complains
about this when the fix is in-place:
valgrind --leak-check=full --trace-children=yes --suppressions=valgrind.supp target/debug/deps/glommio-d6605e578a7ecc14 executor::test::executor_shutdown_does_not_leak_eventfds
Before (test leaks about ~32 MiB if I'm not mistaken):
==3196979== Memcheck, a memory error detector
==3196979== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==3196979== Using Valgrind-3.23.0.GIT and LibVEX; rerun with -h for copyright info
==3196979== Command: target/debug/deps/glommio-d6605e578a7ecc14 executor::test::executor_shutdown_does_not_leak_eventfds
==3196979==
running 1 test
test executor::test::executor_shutdown_does_not_leak_eventfds ... FAILED
failures:
---- executor::test::executor_shutdown_does_not_leak_eventfds stdout ----
thread 'executor::test::executor_shutdown_does_not_leak_eventfds' (3196981) panicked at /home/vlovich/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rusty-fork-0.3.1/src/fork_test.rs:135:9:
child exited unsuccessfully with exit status: 70
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
==3196982== Memcheck, a memory error detector
==3196982== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==3196982== Using Valgrind-3.23.0.GIT and LibVEX; rerun with -h for copyright info
==3196982== Command: /home/vlovich/projects/byte-harbor/glommio/target/debug/deps/glommio-d6605e578a7ecc14 --quiet --test-threads 1 --nocapture --exact -- executor::test::executor_shutdown_does_not_leak_eventfds
==3196982==
running 1 test
thread 'executor::test::executor_shutdown_does_not_leak_eventfds' (3196989) panicked at glommio/src/executor/mod.rs:2953:13:
assertion `left == right` failed: eventfds leaked after 10 rounds
left: 21
right: 1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
<huge report of all the leaks>
==3196982==
==3196982== LEAK SUMMARY:
==3196982== definitely lost: 0 bytes in 0 blocks
==3196982== indirectly lost: 0 bytes in 0 blocks
==3196982== possibly lost: 28,476 bytes in 435 blocks
==3196982== still reachable: 4,193 bytes in 40 blocks
==3196982== suppressed: 560 bytes in 1 blocks
==3196982== Reachable blocks (those to which a pointer was found) are not shown.
==3196982== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3196982==
==3196982== For lists of detected and suppressed errors, rerun with: -s
==3196982== ERROR SUMMARY: 12 errors from 12 contexts (suppressed: 1 from 1)
failures:
executor::test::executor_shutdown_does_not_leak_eventfds
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 399 filtered out; finished in 2.26s
==3196979==
==3196979== HEAP SUMMARY:
==3196979== in use at exit: 866 bytes in 7 blocks
==3196979== total heap usage: 1,058 allocs, 1,051 frees, 1,439,425 bytes allocated
==3196979==
==3196979== LEAK SUMMARY:
==3196979== definitely lost: 0 bytes in 0 blocks
==3196979== indirectly lost: 0 bytes in 0 blocks
==3196979== possibly lost: 0 bytes in 0 blocks
==3196979== still reachable: 818 bytes in 6 blocks
==3196979== suppressed: 48 bytes in 1 blocks
After:
==3202589== Memcheck, a memory error detector
==3202589== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==3202589== Using Valgrind-3.23.0.GIT and LibVEX; rerun with -h for copyright info
==3202589== Command: target/debug/deps/glommio-d6605e578a7ecc14 executor::test::executor_shutdown_does_not_leak_eventfds
==3202589==
running 1 test
test executor::test::executor_shutdown_does_not_leak_eventfds ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 399 filtered out; finished in 3.35s
==3202589==
==3202589== HEAP SUMMARY:
==3202589== in use at exit: 592 bytes in 2 blocks
==3202589== total heap usage: 1,043 allocs, 1,041 frees, 968,940 bytes allocated
==3202589==
==3202589== LEAK SUMMARY:
==3202589== definitely lost: 0 bytes in 0 blocks
==3202589== indirectly lost: 0 bytes in 0 blocks
==3202589== possibly lost: 0 bytes in 0 blocks
==3202589== still reachable: 544 bytes in 1 blocks
==3202589== suppressed: 48 bytes in 1 blocks
==3202589== Reachable blocks (those to which a pointer was found) are not shown.
==3202589== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3202589==
==3202589== For lists of detected and suppressed errors, rerun with: -s
==3202589== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1 from 1)
The "still reachable" is what we suppressed and is only in the parent
report (child doesn't report any leaks).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
This fixes the memory leak and makes it safe to create executors and destroy them without leaking memory.
Motivation
I figured I'd point Codex at the problem and it turns out the fix was straightforward.
Related issues
#448
Additional Notes
I verified this also in Valgrind.
valgrind --leak-check=full --trace-children=yes --suppressions=valgrind.supp target/debug/deps/glommio-d6605e578a7ecc14 executor::test::executor_shutdown_does_not_leak_eventfds
Before the fix it prints (twice because the test itself is within a spawned subprocess):
After the fix it's completely clean:
Checklist
[X] I have added unit tests to the code I am submitting
[X] My unit tests cover both failure and success scenarios
[X] If applicable, I have discussed my architecture