From e66bcf38e7a0d5906c71a88a014b176f12e800a7 Mon Sep 17 00:00:00 2001 From: Tyler Hobbs Date: Thu, 17 Oct 2013 12:13:52 -0500 Subject: [PATCH] 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 --- cassandra/io/asyncorereactor.py | 7 ++++++- cassandra/io/libevreactor.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cassandra/io/asyncorereactor.py b/cassandra/io/asyncorereactor.py index 0aca79e6..02b78d53 100644 --- a/cassandra/io/asyncorereactor.py +++ b/cassandra/io/asyncorereactor.py @@ -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: diff --git a/cassandra/io/libevreactor.py b/cassandra/io/libevreactor.py index 792cdb48..0db6e298 100644 --- a/cassandra/io/libevreactor.py +++ b/cassandra/io/libevreactor.py @@ -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: