Skip to content

Commit

Permalink
fs: fix missing 'error' event in (Read|Write)Stream#destroy
Browse files Browse the repository at this point in the history
fs.ReadStream / fs.WriteStream destroy([error]) function
should emit 'error' event if `error` is set.

PR-URL: #19735
Fixes: #19727
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
range3 authored and BridgeAR committed Apr 9, 2018
1 parent 9c06770 commit 6e2d5af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ ReadStream.prototype._destroy = function(err, cb) {
return;
}

closeFsStream(this, cb);
closeFsStream(this, cb, err);
this.fd = null;
};

Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-fs-stream-destroy-emit-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

test(fs.createReadStream(__filename));
test(fs.createWriteStream(`${tmpdir.path}/dummy`));

function test(stream) {
const err = new Error('DESTROYED');
stream.on('open', function() {
stream.destroy(err);
});
stream.on('error', common.mustCall(function(err_) {
assert.strictEqual(err_, err);
}));
}

0 comments on commit 6e2d5af

Please sign in to comment.