Skip to content

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

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

Closed
ixcat opened this issue Mar 26, 2021 · 1 comment
Closed
Labels
bug Indicates an unexpected problem or unintended behavior stale Indicates issues, pull requests, or discussions are inactive

Comments

@ixcat
Copy link

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

@ixcat ixcat added bug Indicates an unexpected problem or unintended behavior awaiting-triage labels Mar 26, 2021
ixcat pushed a commit to ixcat/datajoint-python that referenced this issue Mar 26, 2021
@guzman-raphael guzman-raphael added this to the Release 0.13.1 milestone Mar 26, 2021
@drewyangdev drewyangdev added the stale Indicates issues, pull requests, or discussions are inactive label Mar 14, 2025
@drewyangdev
Copy link
Contributor

This issue is closed because there has been no activity for more than 365 days, please reopen if it's still applicable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior stale Indicates issues, pull requests, or discussions are inactive
Projects
None yet
Development

No branches or pull requests

3 participants