Skip to content

Commit

Permalink
doc: warn about relying on fs gc close behavior
Browse files Browse the repository at this point in the history
Warn about using the bahvior where file handles are closed automatically
when the file is closed.

PR-URL: #27972
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
benjamingr authored and Trott committed Jun 1, 2019
1 parent dcd0ba1 commit 4c2345f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3733,9 +3733,14 @@ added: v10.0.0

A `FileHandle` object is a wrapper for a numeric file descriptor.
Instances of `FileHandle` are distinct from numeric file descriptors
in that, if the `FileHandle` is not explicitly closed using the
`filehandle.close()` method, they will automatically close the file descriptor
in that they provide an object oriented API for working with files.

If a `FileHandle` is not closed using the
`filehandle.close()` method, it might automatically close the file descriptor
and will emit a process warning, thereby helping to prevent memory leaks.
Please do not rely on this behavior in your code because it is unreliable and
your file may not be closed. Instead, always explicitly close `FileHandle`s.
Node.js may change this behavior in the future.

Instances of the `FileHandle` object are created internally by the
`fsPromises.open()` method.
Expand Down

0 comments on commit 4c2345f

Please sign in to comment.