Handle exceptions when erroring callbacks

In case any of the callbacks don't properly handle exceptions,
handle the exceptions (with a log message) and continue erroring
out the rest of the callbacks.

Related to #48
This commit is contained in:
Tyler Hobbs
2013-10-17 12:13:52 -05:00
parent e73ec7b3a9
commit e66bcf38e7
2 changed files with 12 additions and 2 deletions

View File

@@ -204,7 +204,12 @@ class AsyncoreConnection(Connection, asyncore.dispatcher):
def _error_all_callbacks(self, exc):
new_exc = ConnectionShutdown(str(exc))
for cb in self._callbacks.values():
cb(new_exc)
try:
cb(new_exc)
except Exception:
log.warn("Ignoring unhandled exception while erroring callbacks for a "
"failed connection (%s) to host %s:",
id(self), self.host, exc_info=True)
def handle_connect(self):
with _starting_conns_lock:

View File

@@ -183,7 +183,12 @@ class LibevConnection(Connection):
def _error_all_callbacks(self, exc):
new_exc = ConnectionShutdown(str(exc))
for cb in self._callbacks.values():
cb(new_exc)
try:
cb(new_exc)
except Exception:
log.warn("Ignoring unhandled exception while erroring callbacks for a "
"failed connection (%s) to host %s:",
id(self), self.host, exc_info=True)
def handle_write(self, watcher, revents):
try: