forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: don't end fs promises on Isolate termination
This is specially prevalent in the case of having in-progress FileHandle operations in a worker thread while the Worker is exiting. Fixes: nodejs#42829
- Loading branch information
1 parent
c3aa86d
commit 3e58881
Showing
3 changed files
with
66 additions
and
2 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
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,55 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { | ||
setImmediate, | ||
} = require('timers/promises'); | ||
const { isMainThread, parentPort, Worker } = require('worker_threads'); | ||
|
||
const MAX_ITERATIONS = 20; | ||
const MAX_THREADS = 10; | ||
|
||
if (isMainThread) { | ||
function spinWorker(iter) { | ||
const w = new Worker(__filename, { workerData: iter }); | ||
w.on('message', common.mustCall((msg) => { | ||
assert.strictEqual(msg, 'terminate'); | ||
w.terminate(); | ||
})); | ||
|
||
w.on('exit', common.mustCall(() => { | ||
if (iter < MAX_ITERATIONS) | ||
spinWorker(++iter); | ||
})); | ||
} | ||
|
||
for (let i = 0; i < MAX_THREADS; i++) { | ||
spinWorker(0); | ||
} | ||
} else { | ||
const { promises } = require('fs'); | ||
async function open_close_ok() { | ||
const fh = await promises.open(__filename); | ||
await fh.close(); | ||
await setImmediate(); | ||
await open_close_ok(); | ||
} | ||
|
||
async function open_close_nok() { | ||
await assert.rejects( | ||
promises.open('this file does not exist'), | ||
{ | ||
code: 'ENOENT', | ||
syscall: 'open' | ||
} | ||
); | ||
await setImmediate(); | ||
await open_close_nok(); | ||
} | ||
|
||
open_close_ok(); | ||
open_close_nok(); | ||
|
||
parentPort.postMessage('terminate'); | ||
} |