From 2d8febceef35bdd52624028bdee2e0d58830ae7f Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 23 Jun 2019 08:35:04 -0500 Subject: fs: deprecate closing FileHandle on garbage collection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Tobias Nießen Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott --- src/node_file.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/node_file.cc') 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(); + } }); } -- cgit v1.2.3