From e545f8cbc4d0346085ac5901489c169e9201c255 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 9 May 2019 23:48:37 +0300 Subject: [PATCH] broker stan: fix data race Signed-off-by: Vasiliy Tolstov --- stan.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stan.go b/stan.go index 760ccfe..58a1897 100644 --- a/stan.go +++ b/stan.go @@ -151,6 +151,10 @@ func (n *stanBroker) connect() error { return nil } + n.RLock() + done := n.done + n.RUnlock() + // wait loop for { select { @@ -158,7 +162,7 @@ func (n *stanBroker) connect() error { case <-n.opts.Context.Done(): return nil // call close, don't wait anymore - case <-n.done: + case <-done: return nil // in case of timeout fail with a timeout error case <-timeout: