confluentinc / confluentinc/confluent-kafka-javascript
Request: Support Node Worker Threads using NAN_MODULE_WORKER_ENABLED
- Dominant language
- TypeScript
- Stars
- 304
- Forks
- 45
- Avg merge
- 11h 47m
- Merged PRs (30d)
- 5
Description
Hello,
I recently ran into an issue with the library when running unit tests using `vitest` with the `--pool=threads` option, which uses multiple worker threads to run tests. In my use case, I was getting the following error:
```
Error: Module did not self-register: '/{local_path}/node_modules/.pnpm/@confluentinc+kafka-javascript@1.2.0/node_modules/@confluentinc/kafka-javascript/build/Release/confluent-kafka-javascript.node'.
❯ Module.Hook.Module.require node_modules/.pnpm/dd-trace@5.20.0/node_modules/dd-trace/packages/dd-trace/src/ritm.js:97:33
❯ bindings node_modules/.pnpm/bindings@1.5.0/node_modules/bindings/bindings.js:112:48
❯ Object. node_modules/.pnpm/@confluentinc+kafka-javascript@1.2.0/node_modules/@confluentinc/kafka-javascript/librdkafka.js:10:32
```
After some digging, I found this related [StackOverflow question](https://stackoverflow.com/questions/68598248/is-there-a-way-to-run-native-code-modules-using-worker-threads) - based on their solution, the only change to fix this issue in the library would be changing the following line:
https://github.com/confluentinc/confluent-kafka-javascript/blob/26710e6ec5c8ff8415f2d01dddabb811327c6cde/src/binding.cc#L76
to
```
NAN_MODULE_WORKER_ENABLED(kafka, Init)
```
Is this something that can be added to the library? In the meantime, I can change my testing implementation to use `--pool=forks` option instead, but I would imagine that using the library in worker threads is something that others would find useful at some point.
Contributor guide
Assessment
This issue has not been assessed yet.