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

Error: Module did not self-register. #507

Closed
bdotsamir opened this issue Feb 12, 2020 · 1 comment
Closed

Error: Module did not self-register. #507

bdotsamir opened this issue Feb 12, 2020 · 1 comment

Comments

@bdotsamir
Copy link

What is wrong?

When training network within a worker thread, the thread fails to start and throws Error: Module did not self-register.

Where does it happen?

On Worker thread initialization, node.js v10.19.0 - LTS, KDE Neon (linux) 5.18, base Ubuntu 18.04

How do we replicate the issue?

Require brain.js in the main thread OR worker thread, it seems.
init.js - Main thread

/* eslint-disable */
const brain = require('brain.js'); // NOTE - If you comment this line out, it continues as normal.

const worker = require('worker_threads');
if(!worker.isMainThread) {
  console.error('Called from main thread. Illegal. Exiting...');
  process.exit(1);
} else {
  
  trainBrain()
    .then(console.log)
    .catch(console.error);

}

function trainBrain() {
  return new Promise((resolve, reject) => {
    const child = new worker.Worker('./worker.js', {
      workerData: {
        foo: 'bar',
        num: 1
      }
    });

    child.on('online', () => console.log('Worker online'));
    child.on('message', resolve);
    child.on('error', reject);
  });
}

worker.js - Worker thread

/* eslint-disable */
const worker = require('worker_threads');
const brain = require('brain.js');  // NOTE - If you comment this line out, it continues as normal.

if(worker.isMainThread) {
  console.error('Worker file called at main thread. Illegal. Exiting...');
  process.exit(1);
}

const { workerData } = worker;
const { foo, num } = workerData;

worker.parentPort.postMessage({ foo, num });

How important is this (1-5)?

2?

Expected behavior (i.e. solution)

In init.js OR worker.js, comment out the brain require statement. Somehow, removing the brain.js require seems to fix the issue.

Other Comments

If you're not already aware, worker_threads in node v10.x is an experimental feature, hidden behind the --experimental_worker flag. If you want to enable it, run the command as follows: node --experimental_worker init.js.
https://nodejs.org/dist/latest-v10.x/docs/api/worker_threads.html

image
First try is without the brain require commented out. Second try is with the brain require commented out.

@mubaidr
Copy link
Contributor

mubaidr commented Feb 16, 2020

This is node issue as being discussed here: nodejs/node#21481

In the mean time you could use child_process forks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants