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 <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
benjamingr authored and targos committed Jun 1, 2019
1 parent 6129376 commit c566401
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 c566401

Please sign in to comment.