Visitar URL original
fix: close shebang descriptors after read failures by xiehuanyi · Pull Request #184 · moxystudio/node-cross-spawn · GitHub
Skip to content

fix: close shebang descriptors after read failures - #184

Closed
xiehuanyi wants to merge 1 commit into
moxystudio:masterfrom
xiehuanyi:fix/close-failed-shebang-read-20261011
Closed

xiehuanyi wants to merge 1 commit into
moxystudio:masterfrom
xiehuanyi:fix/close-failed-shebang-read-20261011

Conversation

@xiehuanyi

Copy link
Copy Markdown
Contributor

readShebang closes its file descriptor only after a successful read. If fs.readSync throws (for example, when a directory is encountered), the error is ignored but the opened descriptor leaks.

Close opened descriptors in finally, including descriptor zero. Read and close failures retain the existing non-throwing fallback, and failed opens do not attempt a close.

The new read-failure regression fails on the original code. Additional checks cover failed opens, close errors, and a valid shebang. Validation on Node 22: npm test -- --runInBand passes all 72 tests; npm run lint and git diff --check pass.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 12:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Timbic

Timbic commented Oct 24, 2026

Copy link
Copy Markdown

Hi @xiehuanyi!

Thanks for the fix - this descriptor leak on failed reads is real, and your patch looks good.

Sadly, cross-spawn doesn't seem to be actively maintained anymore. If you're still using it, I maintain
cross-spawn-esm, an ESM/TypeScript drop-in replacement for it.
I've ported your fix there (with regression tests) and added you as a co-author on the commit to credit your work.

Thanks again!

satazor added a commit that referenced this pull request Nov 1, 2026
readShebang only closed the file descriptor after a successful read, so
it leaked when fs.readSync threw, e.g.: when the file is a directory.

Based on #184.

Co-authored-by: Huanyi Xie <74809554+xiehuanyi@users.noreply.github.com>
satazor added a commit that referenced this pull request Nov 1, 2026
readShebang only closed the file descriptor after a successful read, so
it leaked when fs.readSync threw, e.g.: when the file is a directory.

Based on #184.

Co-authored-by: Huanyi Xie <74809554+xiehuanyi@users.noreply.github.com>
@satazor

satazor commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

landed in #187

Thanks!

@satazor satazor closed this Nov 1, 2026
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.

4 participants