datajoint-python icon indicating copy to clipboard operation
datajoint-python copied to clipboard

dj.connection.Connection's connection_id is not updated upon reconnect

Open ixcat opened this issue 4 years ago • 0 comments
trafficstars

Bug Report

Description

Connection's connection_id is not updated upon reconnect.

Reproducibility

while loop printing connection id with kill from mysql session

Expected Behavior

connection id should update & match new ID

Additional Research and Context

copying this snippet from constructor into the reconnect logic appears to do the trick; not sure if this is the best place for it however (should perhaps be done in connect_host_hook or Connection.connect, but not sure of other implications) - can PR if is the desired approach:

$ git diff
diff --git a/datajoint/connection.py b/datajoint/connection.py
index 9db3dcb..f2c2f07 100644
--- a/datajoint/connection.py
+++ b/datajoint/connection.py
@@ -305,6 +305,10 @@ class Connection:
                 raise
             warnings.warn("MySQL server has gone away. Reconnecting to the server.")
             connect_host_hook(self)
+            if self.is_connected:
+                logger.info("Connected {user}@{host}:{port}".format(**self.conn_info))
+                self.connection_id = self.query('SELECT connection_id()').fetchone()[0]
+
             if self._in_transaction:
                 self.cancel_transaction()
                 raise errors.LostConnectionError("Connection was lost during a transaction.")

ixcat avatar Mar 26 '21 02:03 ixcat