From 09f946bd6b2f8b609cb19801a3a8ef96ffc145f1 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 19 Jun 2019 03:09:12 +0300 Subject: [PATCH] stan: fix error when multiple times calling Connect method dont overwrite passed options to avoid error: impossible to use custom ConnectionLostCB and ConnectRetry(true) Signed-off-by: Vasiliy Tolstov --- stan.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stan.go b/stan.go index 091d293..8824b04 100644 --- a/stan.go +++ b/stan.go @@ -218,10 +218,6 @@ func (n *stanBroker) Connect() error { return errors.New("impossible to use custom ConnectionLostCB and ConnectRetry(true)") } - if n.connectRetry { - n.sopts.ConnectionLostCB = n.reconnectCB - } - nopts := []stan.Option{ stan.NatsURL(n.sopts.NatsURL), stan.NatsConn(n.sopts.NatsConn), @@ -229,8 +225,12 @@ func (n *stanBroker) Connect() error { stan.PubAckWait(n.sopts.AckTimeout), stan.MaxPubAcksInflight(n.sopts.MaxPubAcksInflight), stan.Pings(n.sopts.PingInterval, n.sopts.PingMaxOut), - stan.SetConnectionLostHandler(n.sopts.ConnectionLostCB), } + + if n.connectRetry { + nopts = append(nopts, stan.SetConnectionLostHandler(n.reconnectCB)) + } + nopts = append(nopts, stan.NatsURL(strings.Join(n.addrs, ","))) n.nopts = nopts