Fix handling ConnectionClosedOK exception in Relay._receive_messages() #2
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.
If a relay closes the connection to aionostr successfully (not due to an error)
_receive_messages()
will be stuck in a infinite exception loop and block the event loop as it doesn't catchConnectionClosedOK
exception, only theConnectionClosedError
exception.Example:
This PR changes the except to catch the parent exception
ConnectionClosed
which will then attempt to reconnect on both, 'OK' and 'Error' closes.Additionally it checks the return value of
self.connect()
when called inreconnect()
to prevent trying to send if a connection attempt was unsuccessful, instead it will timeout and try again later after the 20 attempts failed.