sarama: Getting: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes.
Sha: 888a76082a Kafka Version: kafka_2.9.2-0.8.2.0
I’ve created a kafka server with 3 nodes, completely based on the quickstart in the kafka documentation.
Everything works fine with the quickstart tutorial, I can create topics, list them, publish and consume. Including the topics listed in the below code. IE the CLI works for ‘NewTopic’ but the code errors out.
However when I attempt to run the producer / simple producer code locally I get this failure:
➜ LegacyProducer go run main.go
> connected
panic: kafka server: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes.
goroutine 16 [running]:
runtime.panic(0x563240, 0x5)
/usr/lib/golang/src/pkg/runtime/panic.c:279 +0xf5
main.main()
/home/glucas/dev/goproj/src/github.com/luck02/LegacyProducer/main.go:70 +0x36f
goroutine 19 [finalizer wait]:
runtime.park(0x4133b0, 0x699808, 0x697ac9)
/usr/lib/golang/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0x699808, 0x697ac9)
/usr/lib/golang/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
/usr/lib/golang/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
/usr/lib/golang/src/pkg/runtime/proc.c:1445
goroutine 23 [chan receive]:
github.com/shopify/sarama.(*Broker).responseReceiver(0xc208004180)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/broker.go:359 +0xdd
github.com/shopify/sarama.*Broker.(github.com/shopify/sarama.responseReceiver)·fm()
/home/glucas/dev/goproj/src/github.com/shopify/sarama/broker.go:113 +0x26
github.com/shopify/sarama.withRecover(0xc208000510)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:42 +0x37
created by github.com/shopify/sarama.func·001
/home/glucas/dev/goproj/src/github.com/shopify/sarama/broker.go:113 +0x381
goroutine 27 [runnable]:
github.com/shopify/sarama.(*Client).backgroundMetadataUpdater(0xc208048090)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/client.go:494 +0x1e0
github.com/shopify/sarama.*Client.(github.com/shopify/sarama.backgroundMetadataUpdater)·fm()
/home/glucas/dev/goproj/src/github.com/shopify/sarama/client.go:80 +0x26
github.com/shopify/sarama.withRecover(0xc208000680)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:42 +0x37
created by github.com/shopify/sarama.NewClient
/home/glucas/dev/goproj/src/github.com/shopify/sarama/client.go:80 +0x4b3
goroutine 44 [runnable]:
github.com/shopify/sarama.withRecover(0xc208001b70)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:32
created by github.com/shopify/sarama.safeAsyncClose
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:51 +0x6c
goroutine 45 [runnable]:
github.com/shopify/sarama.withRecover(0xc208001b80)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:32
created by github.com/shopify/sarama.safeAsyncClose
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:51 +0x6c
goroutine 34 [sleep]:
time.Sleep(0x12a05f200)
/usr/lib/golang/src/pkg/runtime/time.goc:39 +0x31
net.func·019()
/usr/lib/golang/src/pkg/net/dnsclient_unix.go:183 +0x56
created by net.loadConfig
/usr/lib/golang/src/pkg/net/dnsclient_unix.go:212 +0x153
goroutine 47 [runnable]:
github.com/shopify/sarama.withRecover(0xc208001ba0)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:32
created by github.com/shopify/sarama.safeAsyncClose
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:51 +0x6c
goroutine 46 [runnable]:
github.com/shopify/sarama.withRecover(0xc208001b90)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:32
created by github.com/shopify/sarama.safeAsyncClose
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:51 +0x6c
goroutine 43 [runnable]:
github.com/shopify/sarama.func·003()
/home/glucas/dev/goproj/src/github.com/shopify/sarama/producer.go:235 +0x53
github.com/shopify/sarama.withRecover(0xc208001230)
/home/glucas/dev/goproj/src/github.com/shopify/sarama/utils.go:42 +0x37
created by github.com/shopify/sarama.(*Producer).Close
/home/glucas/dev/goproj/src/github.com/shopify/sarama/producer.go:237 +0xae
exit status 2
Code:
func main() {
client, err := sarama.NewClient("UniqueClientID", []string{"192.168.1.76:9092"}, sarama.NewClientConfig())
if err != nil {
panic(err)
} else {
fmt.Println("> connected")
}
defer client.Close()
producer, err := sarama.NewSimpleProducer(client, nil)
if err != nil {
panic(err)
}
defer producer.Close()
for {
err = producer.SendMessage("my_topic", nil, sarama.StringEncoder("testing 123"))
if err != nil {
panic(err)
} else {
fmt.Println("> message sent")
}
}
}
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (5 by maintainers)
use 127.0.0.1 instead of localhost ,it work for me.
Adds [ip-address] [hostname] in your /etc/hosts file. It works for me.