Skip to content

Should metadata response errors trigger connections:connect:error? #155

@jsumners-nr

Description

@jsumners-nr
index.js
const dc = require('node:diagnostics_channel')
const { Producer, stringSerializers } = require('@platformatic/kafka')

dc.subscribe('tracing:plt:kafka:connections:connects:error', (event) => {
  process._rawDebug('!!! error.event: ', event)
})

const producer = new Producer({
  clientId: 'test-producer',
  bootstrapBrokers: ['localhost:9092'],
  serializers: stringSerializers
})

main()
  .then(() => {
    console.log('done')
  })
  .catch((error) => {
    console.error('!!! promise.error: ', error)
  })
  .finally(async () => {
    await producer.close()
  })

async function main() {
  try {
    await producer.send({
      messages: [{
        topic: 'events',
        key: 'user-123',
        value: JSON.stringify({name: 'John', action: 'login'}),
        headers: {source: 'web-app'}
      }]
    })
  } catch (error) {
    console.error('!!! catch.error:', error)
  }
}

If you run that script against a Kafka host that is 1. actively listening on localhost:9092, 2. can serve good connects, and 3. does not have the defined events topic declared, then we'll hit the catch.error but not the error.event. Is this by design or by bug? Note, if you change the port from 9092 to some port that is not listening for anything, e.g. 13337, then the error.event will be hit.

In the case that the connection happens, but the target topic does not exist, the returned error is 4 instances of:

  • msg: Received response with error while executing API Metadata(v12)
  • cause: This server does not host this topic-partition.

If tracing:plt:kafka:connections:connects:error is not the right channel for these metadata errors, which one is?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions