Commit ccacaeed authored by Vincent Pelletier's avatar Vincent Pelletier

Move locking of connection's "close" method call from callers to MTClientConnection class.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@991 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 14c9466f
......@@ -1021,11 +1021,7 @@ class Application(object):
# Due to bug in ZODB, close is not always called when shutting
# down zope, so use __del__ to close connections
for conn in self.em.getConnectionList():
conn.lock()
try:
conn.close()
finally:
conn.release()
# Stop polling thread
self.poll_thread.stop()
close = __del__
......
......@@ -38,11 +38,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
node = app.nm.getNodeByServer(conn.getAddress())
# this must be a master node
if node_type != MASTER_NODE_TYPE:
conn.lock()
try:
conn.close()
finally:
conn.release()
return
if conn.getAddress() != address:
# The server address is different! Then why was
......@@ -50,11 +46,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address)
app.nm.remove(node)
conn.lock()
try:
conn.close()
finally:
conn.release()
return
conn.setUUID(uuid)
......@@ -93,11 +85,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app.primary_master_node = primary_node
if app.trying_master_node is not primary_node:
app.trying_master_node = None
conn.lock()
try:
conn.close()
finally:
conn.release()
else:
if app.primary_master_node is not None:
# The primary master node is not a primary master node
......@@ -105,11 +93,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app.primary_master_node = None
app.trying_master_node = None
conn.lock()
try:
conn.close()
finally:
conn.release()
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list):
pass
......@@ -123,11 +107,7 @@ class PrimaryNotificationsHandler(BaseHandler):
def connectionClosed(self, conn):
app = self.app
logging.critical("connection to primary master node closed")
conn.lock()
try:
conn.close()
finally:
conn.release()
if app.master_conn is conn:
app.master_conn = None
app.primary_master_node = None
......@@ -219,11 +199,7 @@ class PrimaryNotificationsHandler(BaseHandler):
closed = False
conn = self.app.em.getConnectionByUUID(uuid)
if conn is not None:
conn.lock()
try:
conn.close()
finally:
conn.release()
closed = True
if closed and node_type == STORAGE_NODE_TYPE:
# Remove from pool connection
......
......@@ -523,9 +523,12 @@ class MTClientConnection(ClientConnection):
def answer(self, *args, **kw):
return super(MTClientConnection, self).answer(*args, **kw)
@lockCheckWrapper
def close(self, *args, **kw):
return super(MTClientConnection, self).close(*args, **kw)
def close(self):
self.lock()
try:
super(MTClientConnection, self).close()
finally:
self.release()
class MTServerConnection(ServerConnection):
"""A Multithread-safe version of ServerConnection."""
......
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