Fix client file descriptor leaks#2034
Open
hamaaja wants to merge 1 commit intoesnet:masterfrom
Open
Conversation
Close stream buffer fd in `iperf_client_end()`. Close operation is protected by checking if the fd is valid. This prevents double close in case there's a code path calling iperf_free_stream() before iperf_client_end(). Protect stream buffer fd close in `iperf_free_stream()` with fd validity check. This prevent double close in normal test success. Double close is probably fine for close() call but valgrind will nag about it. Close /dev/urandom file in `readentropy()` after reading it. This prevents fd leaks in cases where libiperf is dlopen()'ed, a test is executed and the lib is dlclose()'ed repeatedly.
Contributor
|
Thanks for the PR! We'll take a look at it. |
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.
PLEASE NOTE the following text from the iperf3 license. Submitting a
pull request to the iperf3 repository constitutes "[making]
Enhancements available...publicly":
The complete iperf3 license is available in the
LICENSEfile in thetop directory of the iperf3 source tree.
Version of iperf3 (or development branch, such as
masteror3.1-STABLE) to which this pull request applies:masterand at least releases 3.20 and 3.21Issues fixed (if any): -
Brief description of code changes (suitable for use as a commit message):
Close stream buffer fd in
iperf_client_end(). Close operation is protected by checking if the fd is valid. This prevents double close in case there's a code path callingiperf_free_stream()beforeiperf_client_end().Protect stream buffer fd close in
iperf_free_stream()with fd validity check. This prevent double close in normal test success. Double close is probably fine for close() call but valgrind will nag about it.Close /dev/urandom file in
readentropy()after reading it. This prevents fd leaks in cases where libiperf is dlopen()'ed, a test is executed and the lib is dlclose()'ed repeatedly.Background
We're using iperf as a dynamically loaded library (via dart's foreign function interface) in a long running process. When not in use the library is unloaded. With enough repeats client will run out of file descriptors due to leaks. In normal success case where iperf client ends after given duration (-t option) the
/dev/urandomfile inreadentropy()leaks. This happens because we "forget" the static file in library unloading. "Network unreachable" errors also cause this leak.Another leak happens if the connection to server is lost during the test: The stream buffer fd is not closed in this case.
There may be other leaks as we didn't do extensive testing but these are the ones we're currently running into.
Reproducers
Luckily these leaks are also reproducible in normal command line environment. We're using
valgrindto detect fd leaks and running iperf in Fedora 44 KDE.Version (the current master) and building:
Server command line:
Client command line and valgrind output when test finishes after given duration:
Client command line and valgrind output when test stops because the server is killed (with ctrl-c), equal to our "connection to server is lost" case:
These client leaks get fixed with this PR.