node-rdkafka icon indicating copy to clipboard operation
node-rdkafka copied to clipboard

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

Open asutosh-cgi opened this issue 2 years ago • 4 comments

Environment Information

  • OS [e.g. Mac, Arch, Windows 10]: docker/mac
  • Node Version [e.g. 8.2.1]: 18 an 20
  • NPM Version [e.g. 5.4.2]: 8.5.5
  • C++ Toolchain [e.g. Visual Studio, llvm, g++]:
  • node-rdkafka version [e.g. 2.3.3]: 2.16.9

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

  • Copyright (c) 2016 Blizzard Entertainment
  • Licensed under the MIT License.
  • Original Blizzard node-rdkafka sample modified for use with Azure Event Hubs for Apache Kafka Ecosystems */

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

asutosh-cgi avatar May 11 '23 16:05 asutosh-cgi

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?

leppaott avatar May 17 '23 17:05 leppaott

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.

asutosh-cgi avatar Jul 19 '23 14:07 asutosh-cgi

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

robertlight avatar Dec 05 '23 17:12 robertlight

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

dinssimon avatar Mar 22 '24 07:03 dinssimon