add optional fd leak check#370
Merged
Merged
Conversation
- simplify code around, get rid of unnecessary manual close - use IoHandle for everything so that they are include in the leak check
Coverage Report for CI Build 307Coverage increased (+0.6%) to 79.215%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
This PR introduces an optional fd leak check, which can be enabled by setting the
MOONBIT_ASYNC_CHECK_FD_LEAK. When enabled, themoonbitlang/asyncevent loop will abort if there are unclosed file descriptor managed by the event loop on exit. Currently not much information can be reported on the exact source of the leaked fd, merely the presence of such leak can be known.To make the scope of the leak check wilder, some internal refactor is performed. Most raw fd usage outside
moonbitlang/async/internal/event_loopare eliminated in favor of using@event_loop.IoHandle.is_async=falsecan be used to disable event loop integration of the fd, but still allowing it to get managed by the library, and hence leak-checked. The semantic of@event_loop.IoHandle::from_fdis also refined a bit. It now automatically closes the input fd on failure, this allows eliminating some error handling boilerplate around the codebase when constructing IO handle.Several leaks in the existing codebase are detected by the leak check. They are also fixed in this PR.