-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: guarantee order of callbacks in ws.close
Refactor WriteStream.prototype.close and WriteStream.prototype._destroy to always call the callback passed to close in order. Protects from calling .close() without a callback. Fixes: #17951 See: #15407 PR-URL: #18002 Fixes: #17951 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
0e116a0
commit f148556
Showing
4 changed files
with
77 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/parallel/test-fs-write-stream-close-without-callback.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
common.refreshTmpDir(); | ||
|
||
const s = fs.createWriteStream(path.join(common.tmpDir, 'nocallback')); | ||
|
||
s.end('hello world'); | ||
s.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,45 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
common.refreshTmpDir(); | ||
|
||
const s = fs.createWriteStream(path.join(common.tmpDir, 'rw')); | ||
{ | ||
const s = fs.createWriteStream(path.join(common.tmpDir, 'rw')); | ||
|
||
s.close(common.mustCall()); | ||
s.close(common.mustCall()); | ||
s.close(common.mustCall()); | ||
s.close(common.mustCall()); | ||
} | ||
|
||
{ | ||
const s = fs.createWriteStream(path.join(common.tmpDir, 'rw2')); | ||
|
||
let emits = 0; | ||
s.on('close', () => { | ||
emits++; | ||
}); | ||
|
||
s.close(common.mustCall(() => { | ||
assert.strictEqual(emits, 1); | ||
s.close(common.mustCall(() => { | ||
assert.strictEqual(emits, 1); | ||
})); | ||
process.nextTick(() => { | ||
s.close(common.mustCall(() => { | ||
assert.strictEqual(emits, 1); | ||
})); | ||
}); | ||
})); | ||
} | ||
|
||
{ | ||
const s = fs.createWriteStream(path.join(common.tmpDir, 'rw'), { | ||
autoClose: false | ||
}); | ||
|
||
s.close(common.mustCall()); | ||
s.close(common.mustCall()); | ||
} |