diff options
author | Robert Nagy <ronagy@icloud.com> | 2020-06-20 01:12:44 +0300 |
---|---|---|
committer | Robert Nagy <ronagy@icloud.com> | 2020-06-21 18:23:20 +0300 |
commit | 51a2df4439ea23b5121fcb8e674eb7a3b144cdfa (patch) | |
tree | 09fe52c35d7d11d9c6ab303d8af5a097eab67339 /lib/internal/fs | |
parent | 30cc54275d570a804ced31843d1ff237dd701f85 (diff) |
fs: document why isPerformingIO is required
PR-URL: https://github.com/nodejs/node/pull/33982
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib/internal/fs')
-rw-r--r-- | lib/internal/fs/streams.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 9e6050139dc..0209f3e844c 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -255,6 +255,12 @@ ReadStream.prototype._read = function(n) { }; ReadStream.prototype._destroy = function(err, cb) { + // Usually for async IO it is safe to close a file descriptor + // even when there are pending operations. However, due to platform + // differences file IO is implemented using synchronous operations + // running in a thread pool. Therefore, file descriptors are not safe + // to close while used in a pending read or write operation. Wait for + // any pending IO (kIsPerformingIO) to complete (kIoDone). if (this[kIsPerformingIO]) { this.once(kIoDone, (er) => close(this, err || er, cb)); } else { @@ -416,12 +422,19 @@ WriteStream.prototype._writev = function(data, cb) { }; WriteStream.prototype._destroy = function(err, cb) { + // Usually for async IO it is safe to close a file descriptor + // even when there are pending operations. However, due to platform + // differences file IO is implemented using synchronous operations + // running in a thread pool. Therefore, file descriptors are not safe + // to close while used in a pending read or write operation. Wait for + // any pending IO (kIsPerformingIO) to complete (kIoDone). if (this[kIsPerformingIO]) { this.once(kIoDone, (er) => close(this, err || er, cb)); } else { close(this, err, cb); } }; + WriteStream.prototype.close = function(cb) { if (cb) { if (this.closed) { |