Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move reconnect logic to ConnectionWatchdog #544

Merged
merged 8 commits into from
Jul 12, 2022
Merged

Move reconnect logic to ConnectionWatchdog #544

merged 8 commits into from
Jul 12, 2022

Conversation

jpdillingham
Copy link
Member

The existing reconnect logic executes when a Disconnected event fires, and this event can fire while the client is attempting a connection, which causes the reconnect logic to be executed again, and ultimately a ton of reconnect attempts are made concurrently.

I could have added a semaphore to prevent this re-entrance, but there was no good way to ensure that reconnect logic would continue to execute if a connection connected successfully, but disconnected before the semaphore was released.

This PR adds a ConnectionWatchdog class that uses a timer to check the status of the connection and if the client is disconnected, the reconnect logic is executed. The watchdog starts when a qualifying disconnect event is fired, and stops when a connect event is fired.

There shouldn't be a way for the watchdog to remain disabled, but if so, the logic can be adjusted to run all the time (if the timer interval is increased to maybe 500ms)

Closes #331

@jpdillingham jpdillingham merged commit 9d2ad97 into master Jul 12, 2022
@jpdillingham jpdillingham deleted the reconnect branch July 12, 2022 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Soulseek connection might "thrash" and cause a connect/disconnect cycle
1 participant