Handle exceptions in the sending callback #12
Merged
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.
socket.sendto
can raise some exceptions in which case the callback is repeatedly called as the socket remains writable and the callback stays registered. The exception is simply printed and does not propagate. Thus permanent exceptions effectively cause an infinite loop.One example is trying to ping local network's broadcast or network addresses:
The local machine is on 192.168.192.0/30
I could think of two exceptions that should be retried.
BlockingIOError
. Strictly speaking it should not happen in these circumstances, but I could not find any guarantee in the docs.InterruptedError
should no longer appear in python 3.5 as it now retries syscalls instead of raising it, however I assumed this library could work on py3.4 and kept it.All other exceptions should likely be propagated to the caller.
After these changes (again, the machine is on 192.168.192.0/30):