tulios / kafkajs

A modern Apache Kafka client for node.js
https://kafka.js.org
MIT License
3.75k stars 527 forks source link

Tests - KafkaJSAggregateError: Topic creation errors -- type: 'NOT_CONTROLLER', #1253

Closed helio-frota closed 2 years ago

helio-frota commented 2 years ago

I'm trying to run the tests in a different environment and when running the tests I'm receiving this error when trying to create a topic do you have any fix/workaround or any tip on how to solve it?

This particular error is happening on this test https://github.com/tulios/kafkajs/blob/master/src/admin/__tests__/createTopics.spec.js#L57

thanks

      KafkaJSAggregateError: Topic creation errors
          at Object.parse (/home/lm/code/contrib/kafkajs/src/protocol/requests/createTopics/v0/response.js:29:11)
          at Connection.send (/home/lm/code/contrib/kafkajs/src/network/connection.js:333:35)
          at processTicksAndRejections (node:internal/process/task_queues:96:5)
          at Broker.[private:Broker:sendRequest] (/home/lm/code/contrib/kafkajs/src/broker/index.js:947:14)
          at Broker.createTopics (/home/lm/code/contrib/kafkajs/src/broker/index.js:603:12)
          at /home/lm/code/contrib/kafkajs/src/admin/index.js:141:9
          at Object.<anonymous> (/home/lm/code/contrib/kafkajs/src/admin/__tests__/createTopics.spec.js:62:9)
          at _callCircusTest (/home/lm/code/contrib/kafkajs/node_modules/jest-circus/build/run.js:205:5)
          at _runTest (/home/lm/code/contrib/kafkajs/node_modules/jest-circus/build/run.js:142:3)
          at _runTestsForDescribeBlock (/home/lm/code/contrib/kafkajs/node_modules/jest-circus/build/run.js:56:5) {
        errors: [
          KafkaJSCreateTopicError: This is not the correct controller for this cluster
              at map (/home/lm/code/contrib/kafkajs/src/protocol/requests/createTopics/v0/response.js:32:18)
              at Array.map (<anonymous>)
              at Object.parse (/home/lm/code/contrib/kafkajs/src/protocol/requests/createTopics/v0/response.js:31:23)
              at Connection.send (/home/lm/code/contrib/kafkajs/src/network/connection.js:333:35)
              at processTicksAndRejections (node:internal/process/task_queues:96:5)
              at Broker.[private:Broker:sendRequest] (/home/lm/code/contrib/kafkajs/src/broker/index.js:947:14)
              at Broker.createTopics (/home/lm/code/contrib/kafkajs/src/broker/index.js:603:12)
              at /home/lm/code/contrib/kafkajs/src/admin/index.js:141:9
              at Object.<anonymous> (/home/lm/code/contrib/kafkajs/src/admin/__tests__/createTopics.spec.js:62:9)
              at _callCircusTest (/home/lm/code/contrib/kafkajs/node_modules/jest-circus/build/run.js:205:5) {
            retriable: true,
            helpUrl: undefined,
            type: 'NOT_CONTROLLER',
            code: 41,
            topic: 'test-topic-2eed953ecda7482c0840-25897-c6d1e008-6b1e-4b9e-8dc4-ad62d27f2ca7'
          }
        ]
      }
helio-frota commented 2 years ago

it seems to be something with the admin code because I was able to create the topic using the broker code. example:

Working

const cluster = createCluster()
await cluster.refreshMetadata()
const broker = await cluster.findControllerBroker()
try {
  const result = await broker.createTopics({
    waitForLeaders: false,
    topics: [{ topic: topicName, numPartitions: 1, replicationFactor: 3 }],
  })
} catch (error) {
  console.error(error)
}

This is not working for me:

admin = createAdmin({ cluster: createCluster(), logger: newLogger() })
await admin.connect()
try {
  const result = await admin.createTopics({
    waitForLeaders: false,
    topics: [{ topic: topicName, numPartitions: 1, replicationFactor: 3 }],
  })
} catch (error) {
  console.error(error)
}

But the fact is that I'm using KafkaJS integration tests against other Kafka and makes no sense for me to change this integration test upstream.

helio-frota commented 2 years ago

There is a significant difference related to topic creation between broker and admin code?

helio-frota commented 2 years ago

I found the issue. I need to change the ssl connection options to ssl: true, instead of the existing configuration on the testHelpers. https://github.com/tulios/kafkajs/blob/master/testHelpers/index.js#L46

This is causing the not_controller issue I described above in previous comments.