Skip to content

worker threads throws exception while loading npm lib #21783

Description

@danrevah

the following code fails if I'm trying to run it, seems the problem comes from the marked line below.

const {
  Worker, isMainThread, parentPort, workerData
} = require('worker_threads');

const Kafka = require('node-rdkafka'); // <-- Problemetic line..

if (isMainThread)
{
  console.log('main thread');
  const worker = new Worker(__filename, {
    workerData: 1
  });

  worker.on('message', (args) => console.log('got message from worker', args));
  worker.on('error', (args) => console.log('got error from worker', args));
  worker.on('exit', (code) => {
    if (code !== 0)
      console.log(`Worker stopped with exit code ${code}`);
  });

} else {
  const script = workerData;
  parentPort.postMessage(2);
}

'node-rdkafka' is a external library I'm using, and I was tempted to try and see if I could improve performance with the new worker threads.

while a worker is loaded, there's an error thrown saying 'Module did not self-register'.

this lib does work perfectly without the worker thread.

got error from worker Error: Module did not self-register.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:718:18)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at bindings (/Users/danrevah/dev/git/tmp-librdkafka/node_modules/bindings/bindings.js:81:44)
    at Object.<anonymous> (/Users/danrevah/dev/git/tmp-librdkafka/node_modules/node-rdkafka/librdkafka.js:10:32)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
  • Version: 10.6.0
  • Platform: Darwin Dans-MacBook-Pro.local 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64

Angular 4-6+ Pipes - https://github.com/danrevah/ngx-pipes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    addonsIssues and PRs related to native addons.workerIssues and PRs related to the worker_threads module and Worker API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions