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):
# 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.close()
conn.lock()
try:
conn.close()
finally:
conn.release()
# Stop polling thread
self.poll_thread.stop()
close = __del__
......
......@@ -34,7 +34,11 @@ class PrimaryBaseHandler(BaseHandler):
app = self.app
if app.master_conn is not None:
assert conn is app.master_conn
app.master_conn.close()
app.master_conn.lock()
try:
app.master_conn.close()
finally:
app.master_conn.release()
app.master_conn = None
app.primary_master_node = None
......@@ -100,7 +104,11 @@ class PrimaryBootstrapHandler(BaseHandler):
node = app.nm.getNodeByServer(conn.getAddress())
# this must be a master node
if node_type != MASTER_NODE_TYPE:
conn.close()
conn.lock()
try:
conn.close()
finally:
conn.release()
return
if conn.getAddress() != (ip_address, port):
# The server address is different! Then why was
......@@ -109,7 +117,11 @@ class PrimaryBootstrapHandler(BaseHandler):
conn.getAddress()[0], conn.getAddress()[1],
ip_address, port)
app.nm.remove(node)
conn.close()
conn.lock()
try:
conn.close()
finally:
conn.release()
return
conn.setUUID(uuid)
......@@ -149,7 +161,11 @@ class PrimaryBootstrapHandler(BaseHandler):
app.primary_master_node = primary_node
if app.trying_master_node is not primary_node:
app.trying_master_node = None
conn.close()
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
......@@ -157,7 +173,11 @@ class PrimaryBootstrapHandler(BaseHandler):
app.primary_master_node = None
app.trying_master_node = None
conn.close()
conn.lock()
try:
conn.close()
finally:
conn.release()
def handleAnswerPartitionTable(self, conn, packet, ptid, row_list):
pass
......@@ -304,7 +324,11 @@ class PrimaryNotificationsHandler(PrimaryBaseHandler):
state != RUNNING_STATE:
for conn in self.app.em.getConnectionList():
if conn.getUUID() == n.getUUID():
conn.close()
conn.lock()
try:
conn.close()
finally:
conn.release()
break
if node_type == STORAGE_NODE_TYPE:
# Remove from pool connection
......
......@@ -76,7 +76,11 @@ class StorageBootstrapHandler(StorageBaseHandler):
node = app.nm.getNodeByServer(conn.getAddress())
# It can be eiter a master node or a storage node
if node_type != STORAGE_NODE_TYPE:
conn.close()
conn.lock()
try:
conn.close()
finally:
conn.release()
return
if conn.getAddress() != (ip_address, port):
# The server address is different! Then why was
......@@ -84,7 +88,11 @@ class StorageBootstrapHandler(StorageBaseHandler):
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], ip_address, port)
app.nm.remove(node)
conn.close()
conn.lock()
try:
conn.close()
finally:
conn.release()
return
conn.setUUID(uuid)
......
......@@ -507,6 +507,10 @@ 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)
class MTServerConnection(ServerConnection):
"""A Multithread-safe version of ServerConnection."""
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