Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for reloading module in multiple workers #402

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/module/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@ void init(Local<Object> target) {

} // namespace ivm

NODE_MODULE_CONTEXT_AWARE(isolated_vm, ivm::init) // NOLINT
NODE_MODULE_INIT(/* exports, module, context */) {
ivm::init(exports);
}
18 changes: 18 additions & 0 deletions tests/worker-reload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { Worker } = require('worker_threads');

if (process.platform === 'win32') {
// unloading the module segfaults on Windows, skip for now
console.log('pass');
process.exit();
}

(async function () {
for (let i = 0; i < 2; i++) {
const worker = new Worker("require('isolated-vm')", { eval: true });
await new Promise((resolve, reject) => {
worker.on('exit', code => code ? reject(new Error(`Worker exited with code: ${code}`)) : resolve());
worker.on('error', error => reject(error));
});
}
console.log('pass')
})().catch(console.error);
Loading