Blizzard / node-rdkafka

Node.js bindings for librdkafka
MIT License
2.1k stars 390 forks source link

node-rdkafka throwing Segmentation fault for node 18 and 20 for docker and mac os #1014

Open asutosh-cgi opened 1 year ago

asutosh-cgi commented 1 year ago

Environment Information

Steps to Reproduce RUN below code in docker/mac ` /* Copyright (c) Microsoft Corporation. All rights reserved.

var Kafka = require('node-rdkafka');

var producer = new Kafka.Producer({ //'debug' : 'all', 'metadata.broker.list': 'mynamespace.servicebus.windows.net:9093', //REPLACE 'dr_cb': true, //delivery report callback 'security.protocol': 'SASL_SSL', 'sasl.mechanisms': 'PLAIN', 'sasl.username': '$ConnectionString', //do not replace $ConnectionString 'sasl.password': 'Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=XXXXXX;SharedAccessKey=XXXXXX' //REPLACE });

var topicName = 'test';

//logging debug messages, if debug is enabled producer.on('event.log', function(log) { console.log(log); });

//logging all errors producer.on('event.error', function(err) { console.error('Error from producer'); console.error(err); });

//counter to stop this sample after maxMessages are sent var counter = 0; var maxMessages = 10;

producer.on('delivery-report', function(err, report) { console.log('delivery-report: ' + JSON.stringify(report)); counter++; });

//Wait for the ready event before producing producer.on('ready', function(arg) { console.log('producer ready.' + JSON.stringify(arg));

for (var i = 0; i < maxMessages; i++) { var value = new Buffer({"name" : "person${i}"}"); var key = "key-"+i; // if partition is set to -1, librdkafka will use the default partitioner var partition = -1; producer.produce(topicName, partition, value, key); }

//need to keep polling for a while to ensure the delivery reports are received var pollLoop = setInterval(function() { producer.poll(); if (counter === maxMessages) { clearInterval(pollLoop); producer.disconnect(); } }, 1000);

});

producer.on('disconnected', function(arg) { console.log('producer disconnected. ' + JSON.stringify(arg)); });

//starting the producer producer.connect();

`

node-rdkafka Configuration Settings

Additional context

leppaott commented 1 year ago

Better check how you install dependencies on docker for an example? Assuming you build from source? Is there pre-built package available on OS or could update some packages? Just today I was setting this up and I got segmentation faults on docker soon after startup. But after I dropped installing other libc packages in favor of build-essential only it started working. Probably nothing wrong with that code but some crappy library issue. Try updating openssl/libssl etc?

asutosh-cgi commented 1 year ago

Hi @leppaott , We are using node-alpine:18 and below packages RUN apk add --no-cache \ g++ \ gcc \ libgcc \ make \ bash RUN apk add --no-cache ca-certificates \ lz4-dev \ musl-dev \ cyrus-sasl-dev \ openssl-dev \ python3 RUN apk add --no-cache --virtual .build-deps gcc zlib-dev libc-dev bsd-compat-headers py-setuptools bash

still we are facing same issue, could you please share a working example.

robertlight commented 9 months ago

Did anyone come up with a solution - I would love to use node-rdkafka with node-18 !!

dinssimon commented 5 months ago

Do we get any update on this issue. i am also facing the same issue. I am using node 20 and node-rdkafka version 2.14.6