From a28169de2ecac5a726bcd34a8b199743aae0bf9d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 22 Jun 2019 00:25:50 +0300 Subject: [PATCH] stan broker, fix race on subscribe Signed-off-by: Vasiliy Tolstov --- stan.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stan.go b/stan.go index 0669af3..57166d4 100644 --- a/stan.go +++ b/stan.go @@ -280,9 +280,13 @@ func (n *stanBroker) Publish(topic string, msg *broker.Message, opts ...broker.P } func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) { + n.RLock() if n.conn == nil { + n.RUnlock() return nil, errors.New("not connected") } + n.RUnlock() + var ackSuccess bool opt := broker.SubscribeOptions{