From 0c3f2c013a57f79e6c8ae4789e65b2ce4d4b4005 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Wed, 2 Dec 2015 20:40:02 +0100 Subject: [PATCH] Handle gaierror in hope to resolve bug #273 --- src/cutecoin/core/net/api/bma/access.py | 11 ++-- src/cutecoin/core/net/node.py | 71 ++++++------------------- 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/src/cutecoin/core/net/api/bma/access.py b/src/cutecoin/core/net/api/bma/access.py index 9c4210cf..671a9d4d 100644 --- a/src/cutecoin/core/net/api/bma/access.py +++ b/src/cutecoin/core/net/api/bma/access.py @@ -7,6 +7,7 @@ import logging from aiohttp.errors import ClientError import asyncio import random +from socket import gaierror import jsonschema from distutils.version import StrictVersion @@ -243,9 +244,7 @@ class BmaAccess(QObject): if '404' in str(e) or '400' in str(e): raise tries += 1 - except ClientError: - tries += 1 - except asyncio.TimeoutError: + except (ClientError, gaierror, asyncio.TimeoutError): tries += 1 except jsonschema.ValidationError as e: logging.debug(str(e)) @@ -277,9 +276,7 @@ class BmaAccess(QObject): if '404' in str(e) or '400' in str(e): raise tries += 1 - except ClientError: - tries += 1 - except asyncio.TimeoutError: + except (ClientError, gaierror, asyncio.TimeoutError): tries += 1 except jsonschema.ValidationError as e: logging.debug(str(e)) @@ -315,7 +312,7 @@ class BmaAccess(QObject): except ValueError as e: if '404' in str(e) or '400' in str(e): raise - except ClientError: + except (ClientError, gaierror): pass except asyncio.TimeoutError: pass diff --git a/src/cutecoin/core/net/node.py b/src/cutecoin/core/net/node.py index 8340806a..a23ce1e9 100644 --- a/src/cutecoin/core/net/node.py +++ b/src/cutecoin/core/net/node.py @@ -15,6 +15,7 @@ from aiohttp.errors import ClientError, DisconnectedError import logging import time import jsonschema +from socket import gaierror from PyQt5.QtCore import QObject, pyqtSignal @@ -316,14 +317,8 @@ class Node(QObject): logging.debug("Error in previous block reply : {0}".format(self.pubkey)) logging.debug(str(e)) self.changed.emit() - except ClientError: - logging.debug("Client error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except DisconnectedError: - logging.debug("Disconnected error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except asyncio.TimeoutError: - logging.debug("Timeout error : {0}".format(self.pubkey)) + except (ClientError, gaierror, asyncio.TimeoutError, DisconnectedError) as e: + logging.debug("{0} : {1}".format(str(e), self.pubkey)) self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) @@ -342,14 +337,8 @@ class Node(QObject): logging.debug("Error in block reply : {0}".format(self.pubkey)) logging.debug(str(e)) self.changed.emit() - except ClientError: - logging.debug("Client error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except DisconnectedError: - logging.debug("Disconnected error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except asyncio.TimeoutError: - logging.debug("Timeout error : {0}".format(self.pubkey)) + except (ClientError, gaierror, asyncio.TimeoutError, DisconnectedError) as e: + logging.debug("{0} : {1}".format(str(e), self.pubkey)) self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) @@ -383,14 +372,8 @@ class Node(QObject): logging.debug("Error in peering reply : {0}".format(str(e))) self.state = Node.OFFLINE self.changed.emit() - except ClientError: - logging.debug("Client error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except asyncio.TimeoutError: - logging.debug("Timeout error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except DisconnectedError: - logging.debug("Disconnected error : {0}".format(self.pubkey)) + except (ClientError, gaierror, asyncio.TimeoutError, DisconnectedError) as e: + logging.debug("{0} : {1}".format(str(e), self.pubkey)) self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) @@ -417,14 +400,8 @@ class Node(QObject): logging.debug("Error in summary : {0}".format(e)) self.state = Node.OFFLINE self.changed.emit() - except ClientError: - logging.debug("Client error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except asyncio.TimeoutError: - logging.debug("Timeout error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except DisconnectedError: - logging.debug("Disconnected error : {0}".format(self.pubkey)) + except (ClientError, gaierror, asyncio.TimeoutError, DisconnectedError) as e: + logging.debug("{0} : {1}".format(str(e), self.pubkey)) self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) @@ -459,14 +436,8 @@ class Node(QObject): logging.debug("error in uid reply") self.state = Node.OFFLINE self.identity_changed.emit() - except ClientError: - logging.debug("Client error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except asyncio.TimeoutError: - logging.debug("Timeout error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except DisconnectedError: - logging.debug("Disconnected error : {0}".format(self.pubkey)) + except (ClientError, gaierror, asyncio.TimeoutError, DisconnectedError) as e: + logging.debug("{0} : {1}".format(str(e), self.pubkey)) self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) @@ -500,14 +471,8 @@ class Node(QObject): logging.debug("Error in leaf reply") self.state = Node.OFFLINE self.changed.emit() - except ClientError: - logging.debug("Client error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except asyncio.TimeoutError: - logging.debug("Timeout error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except DisconnectedError: - logging.debug("Disconnected error : {0}".format(self.pubkey)) + except (ClientError, gaierror, asyncio.TimeoutError, DisconnectedError) as e: + logging.debug("{0} : {1}".format(str(e), self.pubkey)) self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) @@ -518,14 +483,8 @@ class Node(QObject): logging.debug("Error in peers reply") self.state = Node.OFFLINE self.changed.emit() - except ClientError: - logging.debug("Client error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except asyncio.TimeoutError: - logging.debug("Timeout error : {0}".format(self.pubkey)) - self.state = Node.OFFLINE - except DisconnectedError: - logging.debug("Disconnected error : {0}".format(self.pubkey)) + except (ClientError, gaierror, asyncio.TimeoutError, DisconnectedError) as e: + logging.debug("{0} : {1}".format(str(e), self.pubkey)) self.state = Node.OFFLINE except jsonschema.ValidationError: logging.debug("Validation error : {0}".format(self.pubkey)) -- GitLab