question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnhandledPromiseRejectionWarning is shown with exception KafkaJSNumberOfRetriesExceeded for connect()

See original GitHub issue

This only actually happens when there are multiple consumers trying to connect at the same time. This warning is not shown when there is only one consumer.

Also, it is only in the first connect() and Kafka is not available

{"level":"ERROR","timestamp":"2019-07-06T17:27:49.140Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to seed broker, trying another broker from the list: Connection error: connect ECONNREFUSED 127.0.0.1:9092","retryCount":5,"retryTime":9178}
(node:13288) UnhandledPromiseRejectionWarning: KafkaJSNumberOfRetriesExceeded
  Caused by: KafkaJSConnectionError: Connection error: connect ECONNREFUSED 127.0.0.1:9092
    at Socket.onError (/Users/psilva/development/projects/manhattanportal/node_modules/kafkajs/src/network/connection.js:136:23)
    at Socket.emit (events.js:194:15)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
(node:13288) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13288) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Code for connecting:

this._consumer.connect()
                .then(r =>
                    this._consumer.subscribe({
                        fromBeginning: false,
                        topic: this._topic
                    }))
                .then(r => {
                    return this._consumer.run({
                        autoCommit: true,
                        autoCommitInterval: global.kafkaAutoCommitInterval,
                        autoCommitThreshold: global.kafkaAutoCommitThreshold,
                        eachMessage: (p) => {
                            try {
                                this.processMessage(p);
                            }
                            catch(e) {
                                   // log error
                            }
                            return Promise.resolve();
                        }
                    })
                })
                .catch(e => {
                    if(e.retriable === false) {
                        // consumer failed to connect and won't keep retrying
                        // perform shutdown and reconnect

                        setTimeoutPromise(global.kafkaConnectInterval).then(() => this._consumer.disconnect()).then(() => this.connect());
                    }

                    this.emit("error", e);
                });
        }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Nevoncommented, Jul 27, 2019

The reasoning behind our release strategy is documented here: https://kafka.js.org/docs/pre-releases

As of yesterday, we publish pre-release versions on every push to master, that you can install via the beta tag.

1reaction
tulioscommented, Jul 26, 2019

The broker is correct; it should propagate the error. The fix is probably higher up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Kafka.JS refuses to connect <<[BrokerPool] Failed ...
I was trying to reproduce the same issue. But this code is working fine with brokers: ['localhost:9092'] . There is no issue with...
Read more >
Unable to connect with node.js due to "mongodb+srv"
I'm having the EXACT same error as Getting error upon await client.connect() in node.JS and Error with await client.connect() node.JS.
Read more >
the producer attempted to use a producer id which is not ...
I'm always receiving an exception saying that "The producer attempted to use a ... code used is there) and while testing the solutions...
Read more >
Client Configuration - KafkaJS
After successfully connecting to a broker in this list, Kafka has its own mechanism for discovering the rest of the cluster.
Read more >
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found