huobi_Golang icon indicating copy to clipboard operation
huobi_Golang copied to clipboard

Infinite reconnecting loop

Open filinvadim opened this issue 4 years ago • 7 comments

Guys you don't reset p.lastReceivedTime variable while reconnect so that's cause infinite reconnecting loop.

filinvadim avatar Nov 22 '20 10:11 filinvadim

@filinvadim thanks for your question, p.lastReceivedTime will not be reset (=time.Now()) until it reads something from remote server. If you see infinitie reconnecting loop, that’s indicate you didn’t successfully read message from remote server after reconnecting before the timeout. The default timeout (ReconnectWaitSecond) is 60 (1 min).

If you change ReconnectWaitSecond longer, does it resolve your problem?

eynzhang avatar Dec 03 '20 06:12 eynzhang

Reading loop won't have time to get message because connection will be immediately closed due p.lastReceivedTime exceeding. Please reset p.lastReceivedTime. Guys, come on! It's obvious!

filinvadim avatar Dec 03 '20 16:12 filinvadim

Off-top: what the idea of reconnecting for V2 client? Reconnecting logic doesn't do re-subscription. So basically it's useless.

filinvadim avatar Dec 03 '20 16:12 filinvadim

In commit 73530f6, p.startReadLoop() is called only in Connect(). After reconnected, readLoop() has been stopped in disconnectWebSocket() and never be launched again.

cj60205 avatar Jan 09 '21 08:01 cj60205

@cj60205 Yes, that’s the reconnect failure issue introduced. Now it is resolved in latest master branch.

eynzhang avatar Feb 26 '21 10:02 eynzhang

Reading loop won't have time to get message because connection will be immediately closed due p.lastReceivedTime exceeding. Please reset p.lastReceivedTime. Guys, come on! It's obvious!

Reading loop won't have time to get message because connection will be immediately closed due p.lastReceivedTime exceeding. Please reset p.lastReceivedTime. Guys, come on! It's obvious!

I understand the issue but I mentioned incorrect timeout settings in earlier reply. The tickerLoop will check the timeout every 5 seconds, which is defined in TimerIntervalSecond = 5, if you increase TimerIntervalSecond, is that helpful?

We want to understand the issue first and then resolve that. One of the soluiton is as you proposed, reset the p.lastReceivedTime once the websocket connected. So please confirm above work around is working for you.

eynzhang avatar Feb 26 '21 10:02 eynzhang

It won't work. Since lastReceivedTime wasn't reset elapsedSecond will be always bigger than ReconnectWaitSecond.

My WS connection may be idle for hours. Therefore client will start reconnect infinitely.

if appropriate i can propose you all different approach: https://github.com/filinvadim/stubborn

filinvadim avatar Feb 26 '21 11:02 filinvadim