Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,8 @@ ReadStream.prototype.close = function(cb) {
close();

function close(fd) {
if (fd === undefined && self.fd === null)
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not emit an error after it is already closed? Does calling .close() twice on a stream count as a programmer error? If yes, perhaps it shouldn't be thrown under the rug.

fs.close(fd || self.fd, function(er) {
if (er)
self.emit('error', er);
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-fs-read-stream-double-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const common = require('../common');
const fs = require('fs');

common.refreshTmpDir();
fs.writeFileSync(common.tmpDir + '/ro', '');

const s = fs.createReadStream(common.tmpDir + '/ro');
s.close(common.mustCall(function() {}));
s.close(common.mustCall(function() {}));
10 changes: 10 additions & 0 deletions test/parallel/test-fs-write-stream-double-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const common = require('../common');
const fs = require('fs');

common.refreshTmpDir();

const s = fs.createWriteStream(common.tmpDir + '/rw');
s.close(common.mustCall(function() {}));
s.close(common.mustCall(function() {}));