-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: do not emit 'close' twice if emitClose enabled
fs streams have some backwards compat behavior that does not behave well if emitClose: true is passed in options. This fixes this edge case until the backwards compat is removed. PR-URL: #31383 Fixes: #31366 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
- Loading branch information
1 parent
843c5c6
commit 2c2b3ba
Showing
2 changed files
with
23 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
// Test that 'close' emits once and not twice when `emitClose: true` is set. | ||
// Refs: https://github.com/nodejs/node/issues/31366 | ||
|
||
const common = require('../common'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const filepath = path.join(tmpdir.path, 'write_pos.txt'); | ||
|
||
const fileReadStream = fs.createReadStream(process.execPath); | ||
const fileWriteStream = fs.createWriteStream(filepath, { | ||
emitClose: true | ||
}); | ||
|
||
fileReadStream.pipe(fileWriteStream); | ||
fileWriteStream.on('close', common.mustCall()); |