From bcdb522f601c3603bf3d0cbb5496284e4b7ce4af Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Thu, 30 May 2019 12:15:02 +0200 Subject: [PATCH 1/3] doc: warn about relying on fs gc close behavior Warn about using the bahvior where file handles are closed automatically when the file is closed. PR-URL: Reviewed-By: Reviewed-By: --- doc/api/fs.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 3b3c6efd58243f..ad71e1d043cdef 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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 explicitly closed using the +`filehandle.close()` method, they 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. From 6b397074738edbc25d65d584d499b5c7f1405e88 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Thu, 30 May 2019 15:07:44 +0200 Subject: [PATCH 2/3] Update doc/api/fs.md Co-Authored-By: Rich Trott --- doc/api/fs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index ad71e1d043cdef..190ae959bb2cc2 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3735,7 +3735,7 @@ A `FileHandle` object is a wrapper for a numeric file descriptor. Instances of `FileHandle` are distinct from numeric file descriptors in that they provide an object oriented API for working with files. -If a `FileHandle` is not explicitly closed using the +If a `FileHandle` is not closed using the `filehandle.close()` method, they 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 From eefdd6edf33803fc74632827240a2a7eba3aa291 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Thu, 30 May 2019 15:07:51 +0200 Subject: [PATCH 3/3] Update doc/api/fs.md Co-Authored-By: Rich Trott --- doc/api/fs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 190ae959bb2cc2..581af574038d7c 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -3736,7 +3736,7 @@ Instances of `FileHandle` are distinct from numeric file descriptors in that they provide an object oriented API for working with files. If a `FileHandle` is not closed using the -`filehandle.close()` method, they might automatically close the file descriptor +`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.