mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
Revert "fs: fix close listener leak in FileHandle streams"
This reverts commit 8488e1324a.
It was advised that the fix in question is broken since
it will unref the handle multiple times.
Signed-off-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/65387
Refs: https://github.com/nodejs/node/pull/64227
Refs: https://github.com/nodejs/node/issues/64214
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
c79868f102
commit
882a781cfb
2 files changed
+1
-52
No files matched your search
@@ -158,19 +158,7 @@ function importFd(stream, options) {
|
||||
stream[kHandle] = options.fd;
|
||||
stream[kFs] = FileHandleOperations(stream[kHandle]);
|
||||
stream[kHandle][kRef]();
|
||||
|
||||
const onclose = FunctionPrototypeBind(stream.close, stream);
|
||||
options.fd.on('close', onclose);
|
||||
if (options.autoClose === false) {
|
||||
function cleanup() {
|
||||
options.fd.removeListener('close', onclose);
|
||||
options.fd[kUnref]();
|
||||
}
|
||||
stream.once('end', cleanup);
|
||||
stream.once('finish', cleanup);
|
||||
stream.once('error', cleanup);
|
||||
}
|
||||
|
||||
options.fd.on('close', FunctionPrototypeBind(stream.close, stream));
|
||||
return options.fd.fd;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,46 +42,7 @@ async function validateRead() {
|
||||
);
|
||||
}
|
||||
|
||||
async function validateReusedCreateReadStream() {
|
||||
const filePath = path.resolve(tmpDir, 'tmp-reused-stream.txt');
|
||||
fs.writeFileSync(filePath, Buffer.from('ab', 'utf8'));
|
||||
|
||||
const fileHandle = await open(filePath, 'r');
|
||||
try {
|
||||
await buffer(fileHandle.createReadStream({
|
||||
start: 0,
|
||||
end: 0,
|
||||
autoClose: false,
|
||||
}));
|
||||
assert.strictEqual(fileHandle.listenerCount('close'), 0);
|
||||
|
||||
await buffer(fileHandle.createReadStream({
|
||||
start: 1,
|
||||
end: 1,
|
||||
autoClose: false,
|
||||
}));
|
||||
assert.strictEqual(fileHandle.listenerCount('close'), 0);
|
||||
} finally {
|
||||
await fileHandle.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function validateReusedCreateWriteStream() {
|
||||
const filePath = path.resolve(tmpDir, 'tmp-reused-write-stream.txt');
|
||||
const fileHandle = await open(filePath, 'w');
|
||||
try {
|
||||
const stream = fileHandle.createWriteStream({ autoClose: false });
|
||||
stream.end('a');
|
||||
await finished(stream);
|
||||
assert.strictEqual(fileHandle.listenerCount('close'), 0);
|
||||
} finally {
|
||||
await fileHandle.close();
|
||||
}
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
validateWrite(),
|
||||
validateRead(),
|
||||
validateReusedCreateReadStream(),
|
||||
validateReusedCreateWriteStream(),
|
||||
]).then(common.mustCall());
|
||||
Reference in new issue
Block a user