From 6a90e99de43593acda65b0d9cc6d7f8ff4574f00 Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 1 Mar 2018 12:52:41 -0500 Subject: [PATCH] IRCNetwork: do not break on socket BlockingIOError On non-blocking sockets, recv() raises BlockingIOError instead of blocking when there's no data to be read. The correct behaviour is to wait and try again instead of breaking the connection. --- classes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/classes.py b/classes.py index e667a98..9943698 100644 --- a/classes.py +++ b/classes.py @@ -1254,6 +1254,7 @@ utils._proto_utils_class = PyLinkNetworkCoreWithUtils # Used by compatibility w class IRCNetwork(PyLinkNetworkCoreWithUtils): S2S_BUFSIZE = 510 + SOCKET_REPOLL_WAIT = 0.5 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -1512,6 +1513,11 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils): try: data = self._socket.recv(2048) + except BlockingIOError: + log.debug('(%s) No data to read, trying again later...', self.name) + if self._aborted.wait(self.SOCKET_REPOLL_WAIT): + break + continue except OSError: # Suppress socket read warnings from lingering recv() calls if # we've been told to shutdown.