nodejs / nodejs/node

File descriptor 0 might not get closed when used in file stream

Open
#57,905 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

fs
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Just from reading the code it seems the file descriptor 0 is not closed for streams.

https://github.com/nodejs/node/blob/e61937b82cbaec758cceeb08876dd51f976b23c2/lib/internal/fs/streams.js#L117-L127

I have not run any tests to confirm that, but the check in code if (!stream.fd) looks rather clear and does not work for fd 0. The _close function actually sets null, so more null-like check should be there:

https://github.com/nodejs/node/blob/e61937b82cbaec758cceeb08876dd51f976b23c2/lib/internal/fs/streams.js#L129-L134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked sections of lib/internal/fs/streams.js, especially lines 117-134, and trace how the stream’s file descriptor is checked and cleared. Confirm the behavior for descriptor 0 and add coverage for the reported case; done means descriptor 0 is closed without regressing other stream cleanup.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
operating-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.