From 6fbdacc374a9e2c069487f335fc3a9947029b810 Mon Sep 17 00:00:00 2001 From: liuxinfeng Date: Thu, 14 Sep 2023 10:07:00 +0800 Subject: [PATCH] fix: already subscribe to topic --- conn/channel.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/conn/channel.go b/conn/channel.go index f42398d8..b9a7bdfd 100644 --- a/conn/channel.go +++ b/conn/channel.go @@ -382,10 +382,10 @@ func DialChannelWithClient(endpoint string, config *tls.Config, groupID int) (*C if err = ch.handshakeChannel(); err != nil { logrus.Errorf("handshake channel protocol failed, use default protocol version") } - // ch.topicHandlers[blockNotifyPrefix+strconv.Itoa(groupID)] = nil - // if err = ch.sendSubscribedTopics(); err != nil { - // return nil, fmt.Errorf("subscriber block nofity failed") - // } + ch.topicHandlers[blockNotifyPrefix+strconv.Itoa(groupID)] = nil + if err = ch.sendSubscribedTopics(); err != nil { + return nil, fmt.Errorf("subscriber block nofity failed") + } return ch, nil }) } @@ -752,7 +752,7 @@ func (hc *channelSession) subscribeTopic(topic string, handler func([]byte, *[]b if handler == nil { return errors.New("handler is nil") } - if _, ok := hc.topicHandlers[topic]; ok { + if oldHandler, ok := hc.topicHandlers[topic]; ok && oldHandler != nil { return errors.New("already subscribed to topic " + topic) } hc.topicMu.Lock()