Skip to content

add optional fd leak check#370

Merged
Guest0x0 merged 4 commits into
mainfrom
add-leak-check
May 15, 2026
Merged

add optional fd leak check#370
Guest0x0 merged 4 commits into
mainfrom
add-leak-check

Conversation

@Guest0x0

@Guest0x0 Guest0x0 commented May 15, 2026

Copy link
Copy Markdown
Collaborator

This PR introduces an optional fd leak check, which can be enabled by setting the MOONBIT_ASYNC_CHECK_FD_LEAK. When enabled, the moonbitlang/async event 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_loop are eliminated in favor of using @event_loop.IoHandle. is_async=false can 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_fd is 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.

Guest0x0 added 4 commits May 15, 2026 13:45
- simplify code around, get rid of unnecessary manual close
- use IoHandle for everything so that they are include in the leak check
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 307

Coverage increased (+0.6%) to 79.215%

Details

  • Coverage increased (+0.6%) from the base build.
  • Patch coverage: 14 uncovered changes across 5 files (49 of 63 lines covered, 77.78%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
src/internal/event_loop/event_loop.mbt 10 5 50.0%
src/socket/tcp.mbt 8 5 62.5%
src/fs/dir.mbt 8 6 75.0%
src/internal/event_loop/io_unix.mbt 4 2 50.0%
src/internal/event_loop/io_windows.mbt 4 2 50.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4181
Covered Lines: 3312
Line Coverage: 79.22%
Coverage Strength: 59720.74 hits per line

💛 - Coveralls

@Guest0x0
Guest0x0 merged commit ad9880a into main May 15, 2026
28 of 29 checks passed
@Guest0x0
Guest0x0 deleted the add-leak-check branch May 15, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants