grpc-node: Does not support multiple threads
Problem description
If I try to use the grpc library in multiple threads, I get Error: Module did not self-register.
exception.
Reproduction steps
Run with node --experimental-worker
:
import { isMainThread, Worker } from 'worker_threads';
if (isMainThread) {
require('grpc');
new Worker(__filename);
} else {
require('grpc'); // throws: `Error: Module did not self-register.`
}
Environment
- OS name, version and architecture: Windows or Linux
- Node version: 10.12.0
- Node installation method: nvm
- Package name and version: grpc@1.13.1
Additional context
Related issue in node repo with more info: https://github.com/nodejs/node/issues/21783
Proposed fix: https://github.com/nodejs/node/issues/21783#issuecomment-429637117 (The module has to be context-aware.)
This has been already fixed at least in these projects:
Full stack trace:
Error: Module did not self-register.
at Object.Module._extensions..node (internal/modules/cjs/loader.js:717:18)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (...\node_modules\grpc\src\grpc_extension.js:32:13)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 6
- Comments: 16 (6 by maintainers)
@Farenheith Not yet. At the time of opening, it was very experimental and not production-ready. Edit: Actually, like the worker threads as well… Sorry, I don’t remember, maybe I tried or I wanted but it was not supporting what I needed.
As I have already stated on this issue, fixing this depends on the linked nan issue being fixed, and as you can see, that has not yet happened. You should ask in the firestore repository about using grpc-js instead.
Not really a direct dependecy. I want to use Hyperledger Fabric Node SDK with workers. They use grpc-node 😦 Thanks anyway, guess I will figure some other way! 😃
Update: I have filed an issue for nan to support this at nodejs/nan#844.