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

Requiring v8-profiler-next fails across multiple threads. #37

Closed
philz opened this issue Apr 4, 2022 · 2 comments · Fixed by #39
Closed

Requiring v8-profiler-next fails across multiple threads. #37

philz opened this issue Apr 4, 2022 · 2 comments · Fixed by #39

Comments

@philz
Copy link

philz commented Apr 4, 2022

The following script fails with "Module did not self-register" errors using v8-profiler-next 1.5.1. This is similar to #9 and perhaps the fixes haven't been ported over?

I'm currently on Node v12.20.1.

$cat prof.js
const {Worker, isMainThread, parentPort} = require('worker_threads');
const fs = require('fs');

function work() {
    require('v8-profiler-next');
    parentPort.postMessage('hi');
}

if (isMainThread) {
    require('v8-profiler-next');
    new Worker(__filename).on('message', (result) => {
        console.log(result);
    });
} else {
    work();
}
$node --version
v12.20.1
$node prof.js

events.js:291
      throw er; // Unhandled 'error' event
      ^
Error: Module did not self-register: '.../src/hyperbase/node_modules/v8-profiler-next/build/Release/profiler.node'.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1057:18)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (.../src/hyperbase/node_modules/v8-profiler-next/dispatch.js:2:17)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
Emitted 'error' event on Worker instance at:
    at Worker.[kOnErrorMessage] (internal/worker.js:242:10)
    at Worker.[kOnMessage] (internal/worker.js:252:37)
    at MessagePort.<anonymous> (internal/worker.js:168:57)
    at MessagePort.emit (events.js:314:20)
    at MessagePort.onmessage (internal/worker/io.js:80:8)
    at MessagePort.exports.emitMessage (internal/per_context/messageport.js:11:10)
@hyj1991
Copy link
Owner

hyj1991 commented May 9, 2022

Hello, I'll soon refactor v8-profiler-next to be context-aware to support profiling in worker_threads.

@hyj1991
Copy link
Owner

hyj1991 commented May 14, 2022

Landed in 8eea608, you can use [email protected] to do CPU profiling in worker_threads.

@hyj1991 hyj1991 mentioned this issue May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants