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 C++ addon modules occurs 'Error: Module did not self-register.' with Worker Threads #21481

Closed
ledsun opened this issue Jun 23, 2018 · 4 comments
Labels
addons Issues and PRs related to native addons. worker Issues and PRs related to Worker support.

Comments

@ledsun
Copy link

ledsun commented Jun 23, 2018

  • Version: v10.5.0
  • Platform: Darwin nakajimashigeru-no-MacBook-Pro.local 16.7.0 Darwin Kernel Version 16.7.0: Fri Apr 27 17:59:46 PDT 2018; root:xnu-3789.73.13~1/RELEASE_X86_64 x86_64
  • Subsystem: worker

When C++ addon was loaded twice with worker threads, error below occurs:

events.js:167
      throw er; // Unhandled 'error' event
      ^
Error: Module did not self-register.
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:731:18)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at bindings (/Users/shigerunakajima/worker_thread_test/node_modules/bindings/bindings.js:81:44)
    at Object.<anonymous> (/Users/shigerunakajima/worker_thread_test/node_modules/libxmljs/lib/bindings.js:1:99)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
Emitted 'error' event at:
    at Worker.[kOnErrorMessage] (internal/worker.js:281:10)
    at Worker.[kOnMessage] (internal/worker.js:291:37)
    at MessagePort.Worker.(anonymous function).on (internal/worker.js:228:57)
    at MessagePort.emit (events.js:182:13)
    at MessagePort.onmessage (internal/worker.js:57:8)

To reproduce, run code below with --experimental-worker flag:

const libxmljs = require('libxmljs')
const {
  Worker
} = require('worker_threads')

new Worker(__filename)

When I try to require the sharp, same error occurs.

@hlolli
Copy link

hlolli commented Aug 29, 2018

I get the same with node-speaker, I'm on Linux nixos 4.14.63 #1-NixOS SMP Wed Aug 15 16:13:02 UTC 2018 x86_64 GNU/Linux with nodejs 10.7.0. The package node-speaker doesn't work with experimental workers, but works fine otherwise. Like @ledsun I'm also self referencing with __file when constructing a new worker.

@mattolson
Copy link

I'm running into this as well when using experimental workers that try to load the lzo package.

@mattolson
Copy link

This looks to be a duplicate of #21783. It appears that the issue is due to addon initialization -- any native addons that are loaded in both the parent and worker thread (i.e. loaded more than once in the same process) need to be context aware.

I was facing this issue with the node-lzo library and we fixed it in schroffl/node-lzo#11

addaleax added a commit that referenced this issue Feb 25, 2019
Allow loading add-ons from multiple Node.js instances if they are
declared context-aware; in particular, this applies to N-API addons.

Also, plug a memory leak that occurred when registering N-API addons.

Refs: #23319

PR-URL: #26175
Fixes: #21481
Fixes: #21783
Fixes: #25662
Fixes: #20239
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
rvagg pushed a commit that referenced this issue Feb 28, 2019
Allow loading add-ons from multiple Node.js instances if they are
declared context-aware; in particular, this applies to N-API addons.

Also, plug a memory leak that occurred when registering N-API addons.

Refs: #23319

PR-URL: #26175
Fixes: #21481
Fixes: #21783
Fixes: #25662
Fixes: #20239
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
@bdotsamir
Copy link

bdotsamir commented Feb 6, 2020

Issue occurs here too, Linux host-name 5.3.0-28-generic #30~18.04.1-Ubuntu SMP Fri Jan 17 06:14:09 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Package: brain.js
Node.js v10.18.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addons Issues and PRs related to native addons. worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants