kuzzleio / sdk-go

Golang SDK using the WebSocket protocol to communicate with Kuzzle API including offline resiliency
http://docs.kuzzle.io/sdk/go/2
Apache License 2.0
8 stars 5 forks source link

[hotfix] Try to reconnect if the state is not errored #249

Closed jenow closed 5 years ago

jenow commented 5 years ago

What does this PR do?

Try to reconnect if the state is different than Offline and Disconnected and Error.

Before that, we would check only if the state was different than Offline but in the case of when Kuzzle go down and you catch the Disconnected event, then do a Disconnect() to clean and a Reconnect() to try and connect again to the Kuzzle instance, WebSocket would not try to reconnect because the state would be set as Offline which would then initialize some goroutine inside the Kuzzle instance as long as we try to reconnect to the Kuzzle instance and get a OnNetworkError. Once connected to the Kuzzle instance those go routine would still be alive.. for nothing. So if you try to to reconnect to Kuzzle in a loop you would have a serious memory leak.