node-rdkafka
node-rdkafka copied to clipboard
Fix worker_threads support
This makes node-rdkafka work correctly with worker_threads. There were several issues which needed resolving and some changes which were needed to prevent data being shared across threads and to ensure everything is cleaned up completely when the thread exits.
Changes included:
- Use
NODE_MODULE_CONTEXT_AWAREto init module - No globals, shared data needs to live in PerIsolateData.
- No using
uv_default_loop(), need to get the loop owned by the current thread. Dispatcher::Deactivate()on destruct to stopuv_async_tso thread can teardown loop safelyConnectionandTopictypes need cleanup hooks to ensure they are deleted when the thread is torn down.- Construct
Confwith correctly-sized type so destructor and sub-class fields aren't overwriting random memory - Give
AsyncWorkertypes uniqueAsyncResourcenames for better debugging
@GaryWilber can you take a look?
Currently, no native-backed Node.js Kafka library seems to support worker threads...