Commit e0b638b5 authored by Julien Muchembled's avatar Julien Muchembled

client: close failing connection explicitly in case of unhandled exception

The changes consist in:
- indenting many lines without exceeding 80 chars
- setting conn = None ASAP on ConnectionClosed
- adding a try..except clause

Starting from next commit, the exception can be POSException.ReadOnlyError.
parent eb3a3937
......@@ -200,6 +200,8 @@ class Application(ThreadedApplication):
fail_count = 0
ask = self._ask
handler = self.primary_bootstrap_handler
conn = None
try:
while 1:
self.ignore_invalidations = True
# Get network connection to primary master
......@@ -213,10 +215,10 @@ class Application(ThreadedApplication):
# Otherwise, check one by one.
master_list = self.nm.getMasterList()
if not master_list:
# XXX: On shutdown, it already happened that this list
# is empty, leading to ZeroDivisionError. This
# looks a minor issue so let's wait to have more
# information.
# XXX: On shutdown, it already happened that this
# list is empty, leading to ZeroDivisionError.
# This looks a minor issue so let's wait to
# have more information.
logging.error('%r', self.__dict__)
index = (index + 1) % len(master_list)
node = master_list[index]
......@@ -230,6 +232,7 @@ class Application(ThreadedApplication):
try:
ask(conn, p, handler=handler)
except ConnectionClosed:
conn = None
fail_count += 1
else:
self.primary_master_node = node
......@@ -247,9 +250,14 @@ class Application(ThreadedApplication):
if self.pt.operational():
break
except ConnectionClosed:
logging.error('Connection to %s lost', self.trying_master_node)
self.primary_master_node = None
conn = self.primary_master_node = None
logging.error('Connection to %s lost',
self.trying_master_node)
fail_count += 1
except:
if conn is not None:
conn.close()
raise
logging.info("Connected and ready")
return conn
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment