Fix fd leak in RingBuffer; add fd tracking to find leaks (default off; opt-in). #154
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.
This PR fixes a file descriptor (fd) leak in
RingBuffer::Impl
. It also adds some diagnostic tools to try to make it easier to find and diagnose future fd leaks.open
should only be called fromllfs::system_open3
andllfs::system_open2
eventfd
andmemfd
) should be wrapped inllfs::maybe_track_fd
maybe_track_fd
will add a stack trace associated with the passed fd to a global tablellfs/track_fds.hpp
header provides the following API for debugging fd leaks:get_open_fds()
returns a set of the fds currently open by the calling processis_fd_tracking_enabled()
andset_fd_tracking_enabled(bool)
allow querying and modifying the tracker statusget_trace_for_fd(int fd)
will return the last stack trace associated with the passed fd, if there is oneset_trace_for_fd(int fd, stacktrace)
allows a stack trace to be manually associated with a given fdI also took the opportunity to clean up the code in
IoRing::File
, eliminating redundancy by calling existing functions.