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

TypeError: Cannot read property 'host' of undefined #1449

Open
jseparovic opened this issue Jun 28, 2021 · 0 comments
Open

TypeError: Cannot read property 'host' of undefined #1449

jseparovic opened this issue Jun 28, 2021 · 0 comments

Comments

@jseparovic
Copy link

I'm getting TypeError: Cannot read property 'host' of undefined exception when kafka host is reachable but KAFKA_ADVERTISED_LISTENERS is misconfigured, so kafka is not reachable.

Bug Report

Environment

  • Node version: v14.16.1
  • Kafka-node version: 5.0.0
  • Kafka version: 2.7.0

For specific cases also provide

  • Number of Brokers: 1
  • Number partitions for topic: 1

Include Sample Code to reproduce behavior

const kafka = require('kafka-node');
const util = require('util');

const PARTITIONS = 1;
const REPLICATION_FACTOR = 1;

const Client = kafka.KafkaClient;


const createTopic = async (url, topic) => {
    return new Promise((resolve, reject) => {
        try {
            const clientConfig = { // https://github.com/SOHU-Co/kafka-node#kafkaclient
                kafkaHost: url,
                requestTimeout: 5000,
                connectTimeout: 5000,
                connectRetryOptions: { // https://www.npmjs.com/package/retry
                    forever: true,
                },
            };

            const client = new Client(clientConfig);

            const topicsToCreate = [{
                topic: topic,
                partitions: PARTITIONS,
                replicationFactor: REPLICATION_FACTOR,
            }];

            client.createTopics(topicsToCreate, (error, result) => {
                if (error) {
                    reject(error);
                }
                else {
                    if (result[0] && result[0].error) {
                        if (result[0].error.endsWith('already exists.')) {
                            // no worries, carry on
                            console.log(util.format('Topic \'%s\' already exists', topic));
                            resolve();
                        }
                        else {
                            reject(result[0].error);
                        }
                    }
                    else {
                        resolve();
                    }
                }
            });
        }
        catch (error) {
            reject(error);
        }
    });
};

const main = async () => {
    try {
        await createTopic('kafka1:9092', 'testing123');
    }
    catch (error) {
        console.error('error:', error);
    }
};


main();

Include output with Debug turned on

/Users/jason/.nvm/versions/node/v14.17.1/bin/node /Users/jason/plcode/common-libs/common-libs-pubsub/test.js
  kafka-node:KafkaClient Connect attempt 1 +0ms
  kafka-node:KafkaClient Trying to connect to host: kafka1 port: 9092 +2ms
  kafka-node:KafkaClient kafka-node-client createBroker kafka1:9092 +1ms
  kafka-node:KafkaClient missing apiSupport waiting until broker is ready...(loadMetadataForTopics) +10ms
  kafka-node:KafkaClient waitUntilReady [BrokerWrapper kafka1:9092 (connected: true) (ready: false) (idle: false) (needAuthentication: false) (authenticated: false)] +0ms
  kafka-node:KafkaClient kafka-node-client sending versions request to kafka1:9092 +7ms
  kafka-node:KafkaClient broker socket connected {"host":"kafka1","port":9092} +2ms
  kafka-node:KafkaClient connected to socket, trying to load initial metadata +0ms
  kafka-node:KafkaClient missing apiSupport waiting until broker is ready...(loadMetadataForTopics) +1ms
  kafka-node:KafkaClient waitUntilReady [BrokerWrapper kafka1:9092 (connected: true) (ready: false) (idle: false) (needAuthentication: false) (authenticated: false)] +0ms
  kafka-node:KafkaClient Received versions response from kafka1:9092 +3ms
  kafka-node:KafkaClient setting api support to {"21":{"min":0,"max":2,"usable":false},"22":{"min":0,"max":3,"usable":false},"23":{"min":0,"max":3,"usable":false},"24":{"min":0,"max":1,"usable":false},"25":{"min":0,"max":1,"usable":false},"26":{"min":0,"max":1,"usable":false},"27":{"min":0,"max":0,"usable":false},"28":{"min":0,"max":3,"usable":false},"29":{"min":0,"max":2,"usable":false},"30":{"min":0,"max":2,"usable":false},"31":{"min":0,"max":2,"usable":false},"33":{"min":0,"max":1,"usable":false},"34":{"min":0,"max":1,"usable":false},"35":{"min":0,"max":2,"usable":false},"37":{"min":0,"max":2,"usable":false},"38":{"min":0,"max":2,"usable":false},"39":{"min":0,"max":2,"usable":false},"40":{"min":0,"max":2,"usable":false},"41":{"min":0,"max":2,"usable":false},"42":{"min":0,"max":2,"usable":false},"43":{"min":0,"max":2,"usable":false},"44":{"min":0,"max":1,"usable":false},"45":{"min":0,"max":0,"usable":false},"46":{"min":0,"max":0,"usable":false},"47":{"min":0,"max":0,"usable":false},"48":{"min":0,"max":0,"usable":false},"49":{"min":0,"max":0,"usable":false},"produce":{"min":0,"max":8,"usable":2},"fetch":{"min":0,"max":11,"usable":2},"offset":{"min":0,"max":5,"usable":0},"metadata":{"min":0,"max":9,"usable":1},"leader":{"min":0,"max":4,"usable":false},"stopReplica":{"min":0,"max":3,"usable":false},"updateMetadata":{"min":0,"max":6,"usable":false},"controlledShutdown":{"min":0,"max":3,"usable":false},"offsetCommit":{"min":0,"max":8,"usable":2},"offsetFetch":{"min":0,"max":7,"usable":1},"groupCoordinator":{"min":0,"max":3,"usable":0},"joinGroup":{"min":0,"max":7,"usable":0},"heartbeat":{"min":0,"max":4,"usable":0},"leaveGroup":{"min":0,"max":4,"usable":0},"syncGroup":{"min":0,"max":5,"usable":0},"describeGroups":{"min":0,"max":5,"usable":0},"listGroups":{"min":0,"max":4,"usable":0},"saslHandshake":{"min":0,"max":1,"usable":1},"apiVersions":{"min":0,"max":3,"usable":0},"createTopics":{"min":0,"max":5,"usable":1},"deleteTopics":{"min":0,"max":4,"usable":false},"describeConfigs":{"min":0,"max":3,"usable":2},"saslAuthenticate":{"min":0,"max":2,"usable":0}} +0ms
  kafka-node:KafkaClient broker is now ready +0ms
  kafka-node:KafkaClient broker is now ready +1ms
  kafka-node:KafkaClient kafka-node-client updated internal metadata +2ms
/Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/lib/kafkaClient.js:282
    var broker = this.getBroker(controllerMetadata.host, controllerMetadata.port);
                                                   ^

TypeError: Cannot read property 'host' of undefined
    at /Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/lib/kafkaClient.js:282:52
    at /Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/lib/kafkaClient.js:919:7
    at /Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/node_modules/async/dist/async.js:3888:9
    at /Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/node_modules/async/dist/async.js:473:16
    at replenish (/Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/node_modules/async/dist/async.js:1006:25)
    at iterateeCallback (/Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/node_modules/async/dist/async.js:995:17)
    at /Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/node_modules/async/dist/async.js:969:16
    at /Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/node_modules/async/dist/async.js:3885:13
    at KafkaClient.wrappedFn (/Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/lib/kafkaClient.js:481:14)
    at KafkaClient.Client.invokeResponseCallback (/Users/jason/plcode/common-libs/common-libs-pubsub/node_modules/kafka-node/lib/baseClient.js:593:10)
jseparovic pushed a commit to jseparovic/kafka-node that referenced this issue Jun 28, 2021
jseparovic pushed a commit to jseparovic/kafka-node that referenced this issue Jun 28, 2021
jseparovic pushed a commit to jseparovic/kafka-node that referenced this issue Jun 28, 2021
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