Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"[BrokerPool] Failed to connect to seed broker, trying another broker from the list: Connection error: Client network socket disconnected before secure TLS connection was established" #1658

Open
EmmanDizon opened this issue Jan 15, 2024 · 0 comments

Comments

@EmmanDizon
Copy link

EmmanDizon commented Jan 15, 2024

I do not encountered any error when I produce message one time only. But when I executed the producer in loop, I consistently encountering this error "[BrokerPool] Failed to connect to seed broker, trying another broker from the list: Connection error: Client network socket disconnected before secure TLS connection was established"

Another catch, when i try to remove the producer.disconnect (when running in loop), I'm no longer encounter any error, this is consistent, not just intermittent (meaning not a connection issue)

Here is the code for better understanding ->

Here is the calling of producer in array:

async sendEventMessage() {
  const iterations = Array.from({ length: 3 });
      for (const _ of iterations) {
        const message = // any message here
        await this.#kafka.produceEvent(message);
      }
}

Here is the producer:

const { Kafka, Partitioners } = require('kafkajs');

const logger = require('../logger');

class Producer {
  #config;

  #producerInstance;

  constructor(kafkaConfig = {}) {
    this.#config = kafkaConfig;
    this.#producerInstance = this.#initProducer();
  }

  #initProducer() {
    const kafka = new Kafka(this.#config.kafka);
    const producer = kafka.producer({
      ...this.#config?.producer,
      createPartitioner: Partitioners.DefaultPartitioner,
    });
    return producer;
  }

  async produceEvent(events = {}) {
    try {
      await this.#producerInstance.connect();

      await this.#producerInstance.send({
        topic: this.#config.topic,
        acks: -1,
        messages: [events],
      });

      return events;
    } catch (error) {
      logger.error(error.message);
    } finally {
      await this.#producerInstance.disconnect();
    }
  }
}

module.exports = {
  Producer,
};

Here is the calling of async sendEventMessage:

for (const record of records) {
   await sendEventMessage(record)
}

Summary:

  1. No error if i will send/run only producer one at a time
  2. Error occurs when inside loop
  3. No error when inside loop but the producer.disconnect code is removed/disabled via comment

OS: Windows 10
KafkaJS:
"kafkajs": "^2.2.3",
"kafkajs-snappy": "^1.1.0",
Node version: v18.17.1

running the execution in lambda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant