recws-org / recws

Reconnecting WebSocket is a websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped and keeps the connection alive - thread safe!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Infinite loop

atiklabs opened this issue · comments

commented

In got an infinite loop once a day, after profiling the infinite loop is here at around line 375.

		for {
			if !rc.IsConnected() {
				continue
			}

It doesn't go away until I restart my application.

thanks @atik-lab, i think this belongs to #29

could you please try the v1.2.1

commented

Sure, I will let you know if it happens with v1.2.1, usually in a day or two it should happen. In my opinion a small sleep would be good to add there, just to not burn the CPU.

commented

It still get's disconnected and does not connect again and it makes an infinite loop. I will try now with the 1.2.2 and the following code:

			if !rc.IsConnected() {
				rc.CloseAndReconnect()
				return
			}
commented

Hello, I found the error, I was using a module that uses your module and when doing messageType, data, err := b.conn.ReadMessage() had an error it returned without closing properly.

I think you should return in if !rc.IsConnected() { because when reconnecting keepAlive will be called again. Is there any issues when returning in if !rc.IsConnected() {? Is there a main reason why you just had a continue?

Thanks a lot in advance.

For now this will be solved by v1.3.0 in a few mins