State machine for Socket Status and just more robustness #48
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.
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 theElectrumSocket
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 tocreating_threads
or tobroken_creating_sockets
if that failsbroken_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 themexecute_recreation_callback
will call that callback after setting the status took
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 tobroken_killing_threads
broken_killing_threads
will setself.running
to false and wait for the threads to terminate. Especially therecv
thread might not terminate until he get internet connection (again). This might take forever. If all threads are terminated, it will transition tocreating_socket