Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ixcat opened this issue Mar 26, 2021 · 0 comments
Open
Labels

Comments

@ixcat
Copy link
Contributor

ixcat commented Mar 26, 2021

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.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants