-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: #42829 PR-URL: #42910 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
- Loading branch information
1 parent
5c0a24d
commit df50131
Showing
4 changed files
with
106 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
51 changes: 51 additions & 0 deletions
51
test/parallel/test-worker-fshandles-error-on-termination.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,51 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs/promises'); | ||
const { scheduler } = require('timers/promises'); | ||
const { parentPort, Worker } = require('worker_threads'); | ||
|
||
const MAX_ITERATIONS = 20; | ||
const MAX_THREADS = 10; | ||
|
||
// Do not use isMainThread so that this test itself can be run inside a Worker. | ||
if (!process.env.HAS_STARTED_WORKER) { | ||
process.env.HAS_STARTED_WORKER = 1; | ||
|
||
function spinWorker(iter) { | ||
const w = new Worker(__filename); | ||
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 { | ||
async function open_nok() { | ||
await assert.rejects( | ||
fs.open('this file does not exist'), | ||
{ | ||
code: 'ENOENT', | ||
syscall: 'open' | ||
} | ||
); | ||
await scheduler.yield(); | ||
await open_nok(); | ||
} | ||
|
||
// These async function calls never return as they are meant to continually | ||
// open nonexistent files until the worker is terminated. | ||
open_nok(); | ||
open_nok(); | ||
|
||
parentPort.postMessage('terminate'); | ||
} |
46 changes: 46 additions & 0 deletions
46
test/parallel/test-worker-fshandles-open-close-on-termination.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,46 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs/promises'); | ||
const { scheduler } = require('timers/promises'); | ||
const { parentPort, Worker } = require('worker_threads'); | ||
|
||
const MAX_ITERATIONS = 20; | ||
const MAX_THREADS = 10; | ||
|
||
// Do not use isMainThread so that this test itself can be run inside a Worker. | ||
if (!process.env.HAS_STARTED_WORKER) { | ||
process.env.HAS_STARTED_WORKER = 1; | ||
|
||
function spinWorker(iter) { | ||
const w = new Worker(__filename); | ||
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 { | ||
async function open_close() { | ||
const fh = await fs.open(__filename); | ||
await fh.close(); | ||
await scheduler.yield(); | ||
await open_close(); | ||
} | ||
|
||
// These async function calls never return as they are meant to continually | ||
// open and close files until the worker is terminated. | ||
open_close(); | ||
open_close(); | ||
|
||
parentPort.postMessage('terminate'); | ||
} |