From 1af39447433d9994426841d0533cdc3205c6b012 Mon Sep 17 00:00:00 2001 From: Yilun Date: Fri, 24 Apr 2020 16:22:01 -0700 Subject: [PATCH] Reduce reconnectChan len to 0 to avoid infinite reconnect loop Signed-off-by: Yilun --- client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index d435e98f..f56ed7a2 100644 --- a/client.go +++ b/client.go @@ -116,7 +116,7 @@ func NewClient(account *Account, identifier string, config *ClientConfig) (*Clie addressID: addressToID(addr), OnConnect: NewOnConnect(1, nil), OnMessage: NewOnMessage(int(config.MsgChanLen), nil), - reconnectChan: make(chan struct{}, 1), + reconnectChan: make(chan struct{}), responseChannels: cache.New(time.Duration(config.MsgCacheExpiration)*time.Millisecond, time.Duration(config.MsgCacheExpiration)*time.Millisecond), sharedKeys: make(map[string]*[sharedKeySize]byte), wallet: w, @@ -619,7 +619,7 @@ func (c *Client) connect(maxRetries int) error { retryInterval := c.config.MinReconnectInterval for retry := 1; maxRetries == 0 || retry <= maxRetries; retry++ { if retry > 1 { - log.Printf("Retry in %v...\n", retryInterval) + log.Printf("Retry in %v ms...\n", retryInterval) time.Sleep(time.Duration(retryInterval) * time.Millisecond) retryInterval *= 2 if retryInterval > c.config.MaxReconnectInterval { @@ -661,7 +661,7 @@ func (c *Client) handleReconnect() { return } - log.Printf("Reconnect in %v...\n", c.config.MinReconnectInterval) + log.Printf("Reconnect in %v ms...\n", c.config.MinReconnectInterval) time.Sleep(time.Duration(c.config.MinReconnectInterval) * time.Millisecond) err := c.connect(0)