Skip to content

Kafka kafka.DialLeader failed because of encoded partition.Host #591

@voltento

Description

@voltento

Describe the bug
A clear and concise description of what the bug is.
The client can not connect to the kafka leader in docker.

Kafka Version
What version(s) of Kafka are you testing against?
docker image: 'docker.io/bitnami/kafka:2.6.0'

To Reproduce
Steps to reproduce the behavior. Bonus points for a code sample.
Go to https://github.com/voltento/trkaf/tree/fix_kafka_client/

  1. run ' docker-compose up kafka'
  2. run app/main.go which looks like

`
package main

import (
"context"
"github.com/segmentio/kafka-go"
"log"
"time"
)

func main() {
topic := "my-topic"
partition := 0

conn, err := kafka.DialLeader(context.Background(), "tcp", "localhost:9092", topic, partition)
if err != nil {
	log.Fatal("failed to dial leader:", err)
}

conn.SetWriteDeadline(time.Now().Add(10 * time.Second))
_, err = conn.WriteMessages(
	kafka.Message{Value: []byte("one!")},
	kafka.Message{Value: []byte("two!")},
	kafka.Message{Value: []byte("three!")},
)
if err != nil {
	log.Fatal("failed to write messages:", err)
}

if err := conn.Close(); err != nil {
	log.Fatal("failed to close writer:", err)
}

}
`
It faildes with an error: "2021/01/18 18:59:15 dial tcp: lookup 591ebfb6bdec: no such host"

Expected behavior
Connected to the leader.

Additional context
It shows an error: "2021/01/18 18:59:15 dial tcp: lookup 591ebfb6bdec: no such host"
After research I've done I found that the next code
p, err := kafka.DefaultDialer.LookupPartition(context.TODO(), tcp, addr, topic, partition) if err != nil { log.Fatal("can not lookup partition: " + err.Error()) }
works well, it found partition, but the filed p.Host looks like it's encoded and contains the next value "591ebfb6bdec"
So, if I replace it with the value "localhost" and call DialPartition, it works well. F.i.
`
p, err := kafka.DefaultDialer.LookupPartition(context.TODO(), tcp, addr, topic, partition)
if err != nil {
log.Fatal("can not lookup partition: " + err.Error())https://guides.github.com/features/mastering-markdown/
}
p.Leader.Host = "localhost"
conn, err := kafka.DefaultDialer.DialPartition(context.TODO(), tcp, addr, p)

if err != nil {
	log.Fatal("failed to dial leader:", err)
}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions