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

State machine for Socket Status and just more robustness #48

Merged
merged 3 commits into from
Feb 28, 2023

Conversation

k9ert
Copy link
Contributor

@k9ert k9ert commented Feb 28, 2023

The ElectrumSocket did not yet properly reacted to the (un-) healthyness of the underlying socket connection. With this PR, we establish a state-machine which reacts apropriately to (hopefully) all the things which could possibly happen.

The states are stored in the ElectrumSocket.state property. The Constructor of the ElectrumSocket is hardly doing more than just setting up the _monitor_thread which is an endless loop going through these states:

  • creating_sockets will create the sockets and pass to creating_threads or to broken_creating_sockets if that fails
  • broken_creating_sockets will try to create the socket and sleep for some time if that fails (and endlessly try to do that)
  • creating_threads will create the write/recv/ping/notify threads and start them
  • execute_recreation_callback will call that callback after setting the status to ok
  • the ok state will now simply check the other thready and if one of them is no longer alive (probably the ping-thread as he will exit if ping fails for 4 times) it will transition to broken_killing_threads
  • broken_killing_threads will set self.running to false and wait for the threads to terminate. Especially the recv thread might not terminate until he get internet connection (again). This might take forever. If all threads are terminated, it will transition to creating_socket

@k9ert k9ert merged commit 8fcde0a into cryptoadvance:master Feb 28, 2023
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.

None yet

2 participants