Skip to content

Commit e04c8a8

Browse files
kanongilbnoordhuis
authored andcommitted
fs: use correct self reference for autoClose test
1 parent 26a8c0c commit e04c8a8

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

lib/fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ ReadStream.prototype.open = function() {
14941494
var self = this;
14951495
fs.open(this.path, this.flags, this.mode, function(er, fd) {
14961496
if (er) {
1497-
if (this.autoClose) {
1497+
if (self.autoClose) {
14981498
self.destroy();
14991499
}
15001500
self.emit('error', er);

test/simple/test-fs-read-stream.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,27 @@ function file7Next(){
171171
});
172172
file7.on('end', function(err) {
173173
assert.equal(file7.data, 'xyz\n');
174-
process.nextTick(function() {
175-
assert(file7.closed);
176-
assert(file7.destroyed);
177-
});
178174
});
179175
}
180176

181177
// Just to make sure autoClose won't close the stream because of error.
182178
var file8 = fs.createReadStream(null, {fd: 13337, autoClose: false });
183179
file8.on('data', function() {});
184180
file8.on('error', common.mustCall(function() {}));
185-
file8.on('end', function() {
186-
process.nextTick(function() {
187-
assert(!file8.closed);
188-
assert(!file8.destroyed);
189-
assert(file8.fd);
190-
});
181+
182+
// Make sure stream is destroyed when file does not exist.
183+
var file9 = fs.createReadStream('/path/to/file/that/does/not/exist');
184+
file9.on('data', function() {});
185+
file9.on('error', common.mustCall(function() {}));
186+
187+
process.on('exit', function() {
188+
assert(file7.closed);
189+
assert(file7.destroyed);
190+
191+
assert(!file8.closed);
192+
assert(!file8.destroyed);
193+
assert(file8.fd);
194+
195+
assert(!file9.closed);
196+
assert(file9.destroyed);
191197
});

0 commit comments

Comments
 (0)