apache / pulsar-client-node

Apache Pulsar NodeJS Client
https://pulsar.apache.org/
Apache License 2.0
148 stars 86 forks source link

[Bug] Segmentation Fault when using Pulsar Consumer batchReceive #390

Closed rafael-polakiewicz closed 4 months ago

rafael-polakiewicz commented 4 months ago

Description

I encountered a segmentation fault using pulsar consumer batch receive method. The consumer process terminates unexpectedly with a segmentation fault.

Node and pulsar-client info

Steps to Reproduce

1. Start a local instance of Pulsar

Use the following docker-compose file to start a Pulsar instance:

services:
  pulsar:
    image: apachepulsar/pulsar:3.3.0
    command: "bin/pulsar standalone"
    ports:
        - '7128:8080'
        - '6650:6650'
    volumes:
        - pulsar_data:/pulsar/data
        - pulsar_conf:/pulsar/conf

volumes:
  pulsar_data:
  pulsar_conf:

2. Create a simple consumer script

Save the following code in a file named consumer.js:

const Pulsar = require('pulsar-client');

async function main() {
  const client = new Pulsar.Client({
    serviceUrl: 'pulsar://localhost:6650',
  });

  const consumer = await client.subscribe({
    subscription: 'example-subscription',
    subscriptionType: 'Shared',
    topic: 'persistent://public/default/my-topic',
    batchReceivePolicy: {
      timeoutMs: 3000,
      maxNumMessages: 10
    }
  });

  console.log('consumer created');

  while (true) {
    const messages = await consumer.batchReceive();
    messages.forEach(async (msg) => {
      console.log({ msg: msg.getData().toString() });
      await consumer.acknowledge(msg);
    });
  }
}

main();

3. Run the consumer script

Execute the script using the following command:

node consumer.js

4. Create a producer script

Save the following code in a file named producer.js:

const Pulsar = require('pulsar-client');

async function main() {
  const client = new Pulsar.Client({
    serviceUrl: 'pulsar://localhost:6650',
  });

  const producer = await client.createProducer({
    topic: 'persistent://public/default/my-topic',
    blockIfQueueFull: true,
  });

  for (let i = 0; i < 100; i++) {
    console.log(`sent message ${i}`);
    await producer.send({
      data: Buffer.from("test"),
    });
  }
}

main();

5. Populate the topic

Execute the producer script using the following command:

node producer.js

Expected Behavior

The consumer should process and acknowledge messages without errors.

Actual Behavior

The consumer process ends with the following message:

consumer created
zsh: segmentation fault (core dumped)  node consumer.js

Additional Information

I found that the feature request to support batch receive was closed. Am I doing something wrong here, or is this a bug? Please let me know if you need any further information.

Thank you for your attention to this matter.

shibd commented 4 months ago

@rafael-polakiewicz What is the env in which the consumer is running?

can you try this version: npm i pulsar-client@1.11.1-rc.2 --pulsar_binary_host_mirror=https://dist.apache.org/repos/dist/dev/pulsar/pulsar-client-node/

shibd commented 4 months ago

389 can resolve batch_recieve crash issue when the consumer running on Debian system.

iamseki commented 4 months ago

The version pulsar-client@1.11.1-rc.2 works for me. Environment details:

Node.js version:
v18.13.0

npm version:
8.19.3

Operating System details:
Linux [hostname redacted] 6.5.0-41-generic #41~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun  3 11:32:55 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

LSB release information:
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

Package versions:
test-pulsar@1.0.0 /[path redacted]/projects/winston/test-pulsar
└── pulsar-client@1.11.1-rc.2
shibd commented 4 months ago

v1.11.1 has been released, I think it can resolve this issue.

rafael-polakiewicz commented 4 months ago

Thank you, @shibd !! Using v1.11.1 fixed the problem