Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2019-06-23 16:35:04 +0300
committerJames M Snell <jasnell@gmail.com>2020-02-05 05:29:06 +0300
commit2d8febceef35bdd52624028bdee2e0d58830ae7f (patch)
tree6395d55b837bf0bc9237388f3dc206e63e85fb70 /src/node_file.cc
parent018c3e8949e925efc8077801d44c2b2feb974750 (diff)
fs: deprecate closing FileHandle on garbage collection
Closing the FileHandle on garbage collection is a bad practice. Runtime deprecate and indicate that an error will be thrown in the future. PR-URL: https://github.com/nodejs/node/pull/28396 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/node_file.cc')
-rw-r--r--src/node_file.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 0547b2d35de..6436de5a67e 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -205,10 +205,21 @@ inline void FileHandle::Close() {
// If the close was successful, we still want to emit a process warning
// to notify that the file descriptor was gc'd. We want to be noisy about
// this because not explicitly closing the FileHandle is a bug.
+
env()->SetUnrefImmediate([detail](Environment* env) {
ProcessEmitWarning(env,
"Closing file descriptor %d on garbage collection",
detail.fd);
+ if (env->filehandle_close_warning()) {
+ env->set_filehandle_close_warning(false);
+ ProcessEmitDeprecationWarning(
+ env,
+ "Closing a FileHandle object on garbage collection is deprecated. "
+ "Please close FileHandle objects explicitly using "
+ "FileHandle.prototype.close(). In the future, an error will be "
+ "thrown if a file descriptor is closed during garbage collection.",
+ "DEP00XX").IsNothing();
+ }
});
}