Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
For our SDK's the desired functionality if we lose connection is to poll the data directly to collect any updates we missed then re-establish the stream. There were bugs in this area that this pr addresses.
Fixes
retrieve
function it included logic only required on startup i.e. pushing a value to thec.initialized
channel - this meant when called later nobody was listening on the channel and the thread would hang forever.onDisconnect
logic if the stream failed to start up - only if it disconnected, this meant if this path was hit the stream wouldn't start butc.streamConnected
would still be set to true preventing any new streams starting to replace itExponentialBackoff
strategy where it continually tries to reconnect to the stream - because we have our own disconnect logic to poll then start a new stream we don't want this - otherwise we'd end up with 2 streams listening for the same events so we set it toStopBackOff
strategy where it doesn't attempt to re-establish the connection and we can handle itc.streamConnect()
was started as a goroutine - there was no need for this and it defeated the purpose of the rLock we used to control access to this block of code to prevent multiple threads trying to poll/start the streamTesting
Simulate the stream being lost and test that it reconnects after a successful poll, the simplest way to do this is turn off your wifi and wait 5 minutes