Commit 9b0b3fb3 authored by Vincent Pelletier's avatar Vincent Pelletier

Make MTClientConnection.close expect to be called only when protected by a lock.

Add lock/release around each "close" call in client which wasn't already locked.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@769 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent c797d830
...@@ -980,7 +980,11 @@ class Application(object): ...@@ -980,7 +980,11 @@ 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__
......
...@@ -34,7 +34,11 @@ class PrimaryBaseHandler(BaseHandler): ...@@ -34,7 +34,11 @@ class PrimaryBaseHandler(BaseHandler):
app = self.app app = self.app
if app.master_conn is not None: if app.master_conn is not None:
assert conn is app.master_conn assert conn is app.master_conn
app.master_conn.lock()
try:
app.master_conn.close() app.master_conn.close()
finally:
app.master_conn.release()
app.master_conn = None app.master_conn = None
app.primary_master_node = None app.primary_master_node = None
...@@ -100,7 +104,11 @@ class PrimaryBootstrapHandler(BaseHandler): ...@@ -100,7 +104,11 @@ class PrimaryBootstrapHandler(BaseHandler):
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() != (ip_address, port): if conn.getAddress() != (ip_address, port):
# The server address is different! Then why was # The server address is different! Then why was
...@@ -109,7 +117,11 @@ class PrimaryBootstrapHandler(BaseHandler): ...@@ -109,7 +117,11 @@ class PrimaryBootstrapHandler(BaseHandler):
conn.getAddress()[0], conn.getAddress()[1], conn.getAddress()[0], conn.getAddress()[1],
ip_address, port) ip_address, port)
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)
...@@ -149,7 +161,11 @@ class PrimaryBootstrapHandler(BaseHandler): ...@@ -149,7 +161,11 @@ class PrimaryBootstrapHandler(BaseHandler):
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
...@@ -157,7 +173,11 @@ class PrimaryBootstrapHandler(BaseHandler): ...@@ -157,7 +173,11 @@ class PrimaryBootstrapHandler(BaseHandler):
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
...@@ -304,7 +324,11 @@ class PrimaryNotificationsHandler(PrimaryBaseHandler): ...@@ -304,7 +324,11 @@ class PrimaryNotificationsHandler(PrimaryBaseHandler):
state != RUNNING_STATE: state != RUNNING_STATE:
for conn in self.app.em.getConnectionList(): for conn in self.app.em.getConnectionList():
if conn.getUUID() == n.getUUID(): if conn.getUUID() == n.getUUID():
conn.lock()
try:
conn.close() conn.close()
finally:
conn.release()
break break
if node_type == STORAGE_NODE_TYPE: if node_type == STORAGE_NODE_TYPE:
# Remove from pool connection # Remove from pool connection
......
...@@ -76,7 +76,11 @@ class StorageBootstrapHandler(StorageBaseHandler): ...@@ -76,7 +76,11 @@ class StorageBootstrapHandler(StorageBaseHandler):
node = app.nm.getNodeByServer(conn.getAddress()) node = app.nm.getNodeByServer(conn.getAddress())
# It can be eiter a master node or a storage node # It can be eiter a master node or a storage node
if node_type != STORAGE_NODE_TYPE: if node_type != STORAGE_NODE_TYPE:
conn.lock()
try:
conn.close() conn.close()
finally:
conn.release()
return return
if conn.getAddress() != (ip_address, port): if conn.getAddress() != (ip_address, port):
# The server address is different! Then why was # The server address is different! Then why was
...@@ -84,7 +88,11 @@ class StorageBootstrapHandler(StorageBaseHandler): ...@@ -84,7 +88,11 @@ class StorageBootstrapHandler(StorageBaseHandler):
logging.error('%s:%d is waiting for %s:%d', logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], ip_address, port) conn.getAddress()[0], conn.getAddress()[1], ip_address, port)
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)
......
...@@ -507,6 +507,10 @@ class MTClientConnection(ClientConnection): ...@@ -507,6 +507,10 @@ 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, *args, **kw):
return super(MTClientConnection, self).close(*args, **kw)
class MTServerConnection(ServerConnection): class MTServerConnection(ServerConnection):
"""A Multithread-safe version of ServerConnection.""" """A Multithread-safe version of ServerConnection."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
......
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