From d30f3d200b48526d68257bf0ab3df36e4cbac23f Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 13 Nov 2021 18:58:08 +0300 Subject: [PATCH] fix panic on publish with not connected broker Signed-off-by: Vasiliy Tolstov --- kgo.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kgo.go b/kgo.go index a4795dd..6dc893f 100644 --- a/kgo.go +++ b/kgo.go @@ -243,6 +243,12 @@ func (k *kBroker) Publish(ctx context.Context, topic string, msg *broker.Message } func (k *kBroker) publish(ctx context.Context, msgs []*broker.Message, opts ...broker.PublishOption) error { + k.RLock() + if !k.connected { + k.RUnlock() + return broker.ErrNotConnected + } + k.RUnlock() options := broker.NewPublishOptions(opts...) records := make([]*kgo.Record, 0, len(msgs)) var errs []string