confluent-kafka-javascript icon indicating copy to clipboard operation
confluent-kafka-javascript copied to clipboard

Request: Support Node Worker Threads using NAN_MODULE_WORKER_ENABLED

Open nhr-one opened this issue 10 months ago • 1 comments

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/@[email protected]/node_modules/@confluentinc/kafka-javascript/build/Release/confluent-kafka-javascript.node'.
 ❯ Module.Hook.Module.require node_modules/.pnpm/[email protected]/node_modules/dd-trace/packages/dd-trace/src/ritm.js:97:33
 ❯ bindings node_modules/.pnpm/[email protected]/node_modules/bindings/bindings.js:112:48
 ❯ Object.<anonymous> node_modules/.pnpm/@[email protected]/node_modules/@confluentinc/kafka-javascript/librdkafka.js:10:32

After some digging, I found this related StackOverflow question - 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.

nhr-one avatar Feb 17 '25 05:02 nhr-one

I've run into a similar issue in e2e tests using cucumberjs

ktryniszewski-mdsol avatar Apr 04 '25 13:04 ktryniszewski-mdsol