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

MySQL - Lost connection to MySQL server during query #266

Closed
panakouris opened this issue May 2, 2022 · 1 comment · Fixed by #267
Closed

MySQL - Lost connection to MySQL server during query #266

panakouris opened this issue May 2, 2022 · 1 comment · Fixed by #267
Labels
bug Something isn't working

Comments

@panakouris
Copy link
Contributor

panakouris commented May 2, 2022

I finally managed to reproduce this issue mentioned also in #265, and found a possible solution to this. The issue is that after some period of inactivity from the time I was getting the driver with tc.get_driver() to the time I was interacting with the database (for example with driver.get_datasets()), I keep getting this error message OperationalError: (2013, 'Lost connection to MySQL server during query'). From a small test I performed, I saw that the period of inactivity is not always the same, most of the times between 5 and 20 seconds, which means that the reason for the dropped connection is not some hardcoded timeout. The solution that I have tested and seems to work fine is setting pool_pre_ping=True when creating the sqlalchemy engine https://github.com/DHI-GRAS/terracotta/blob/2e8bcdb718bd911569248c0cd1482a29c0ae24a1/terracotta/drivers/relational_meta_store.py#L87 .
From SQLAlchemy docs The “pre ping” feature will normally emit SQL equivalent to “SELECT 1” each time a connection is checked out from the pool; if an error is raised that is detected as a “disconnect” situation, the connection will be immediately recycled, and all other pooled connections older than the current time are invalidated, so that the next time they are checked out, they will also be recycled before use.
I tested up to 400 seconds of inactivity between tc.get_driver() and driver.get_datasets(), and I haven't received any error. What do you think @Nick0693 and @dionhaefner ?

@panakouris panakouris added the bug Something isn't working label May 2, 2022
@dionhaefner
Copy link
Collaborator

Sounds reasonable to me.

panakouris added a commit that referenced this issue May 3, 2022
Co-authored-by: Dion Häfner <[email protected]>
dionhaefner added a commit that referenced this issue May 3, 2022
* Set pool_pre_ping to True

* added comment for issue #266

Co-authored-by: Dion Häfner <[email protected]>

Co-authored-by: Dion Häfner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants