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