broker stan: fix data race

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2019-05-09 23:48:37 +03:00
parent bf0aecf4f6
commit e545f8cbc4

View File

@ -151,6 +151,10 @@ func (n *stanBroker) connect() error {
return nil return nil
} }
n.RLock()
done := n.done
n.RUnlock()
// wait loop // wait loop
for { for {
select { select {
@ -158,7 +162,7 @@ func (n *stanBroker) connect() error {
case <-n.opts.Context.Done(): case <-n.opts.Context.Done():
return nil return nil
// call close, don't wait anymore // call close, don't wait anymore
case <-n.done: case <-done:
return nil return nil
// in case of timeout fail with a timeout error // in case of timeout fail with a timeout error
case <-timeout: case <-timeout: