[Zodb-checkins] CVS: ZODB3/ZEO/zrpc - client.py:1.15 connection.py:1.31

Guido van Rossum guido@python.org
Wed, 18 Sep 2002 23:51:23 -0400


Update of /cvs-repository/ZODB3/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv15377/zrpc

Modified Files:
	client.py connection.py 
Log Message:
The mystery of the Win98 hangs in the checkReconnectSwitch() test
until I added an is_connected() test to testConnection() is solved.

After the ConnectThread has switched the client to the new, read-write
connection, it closes the read-only connection(s) that it was saving
up in case there was no read-write connection.  But closing a
ManagedConnection calls notify_closed() on the manager, which
disconnected the manager and the client from its brand new read-write
connection.  The mistake here is that this should only be done when
closing the manager's current connection!

The fix was to add an argument to notify_closed() that passes the
connection object being closed; notify_closed() returns without doing
a thing when that is not the current connection.

I presume this didn't happen on Linux because there the sockets
happened to connect in a different order, and there was no read-only
connection to close yet (just a socket trying to connect).

I'm taking out the previous "fix" to ClientStorage, because that only
masked the problem in this relatively simple test case.  The problem
could still occur when both a read-only and a read-write server are up
initially, and the read-only server connects first; once the
read-write server connects, the read-write connection is installed,
and then the saved read-only connection is closed which would again
mistakenly disconnect the read-write connection.

Another (related) fix is not to call self.mgr.notify_closed() but to
call self.mgr.connection.close() when reconnecting.  (Hmm, I wonder if
it would make more sense to have an explicit reconnect callback to the
manager and the client?  Later.)


=== ZODB3/ZEO/zrpc/client.py 1.14 => 1.15 ===
--- ZODB3/ZEO/zrpc/client.py:1.14	Tue Sep 17 11:44:55 2002
+++ ZODB3/ZEO/zrpc/client.py	Wed Sep 18 23:51:23 2002
@@ -174,7 +174,11 @@
             finally:
                 self.thread_lock.release()
 
-    def notify_closed(self):
+    def notify_closed(self, conn):
+        if conn is not self.connection:
+            # Closing a non-current connection
+            log("CM.notify_closed() non-current", level=zLOG.BLATHER)
+            return
         log("CM.notify_closed()")
         self.connected = 0
         self.connection = None
@@ -425,7 +429,7 @@
         if self.mgr.connected:
             assert self.preferred
             log("CW: reconnecting client to preferred stub")
-            self.mgr.notify_closed()
+            self.mgr.connection.close()
         try:
             self.client.notifyConnected(self.stub)
         except:


=== ZODB3/ZEO/zrpc/connection.py 1.30 => 1.31 ===
--- ZODB3/ZEO/zrpc/connection.py:1.30	Wed Sep 18 23:25:59 2002
+++ ZODB3/ZEO/zrpc/connection.py	Wed Sep 18 23:51:23 2002
@@ -470,4 +470,4 @@
 
     def close(self):
         self.__super_close()
-        self.__mgr.notify_closed()
+        self.__mgr.notify_closed(self)