1
0
mirror of https://github.com/quay/quay.git synced 2026-01-26 06:21:37 +03:00

database: force close existing non-pooled connections before transaction (PROJQUAY-3303) (#1153)

This hack is for handling possible MySQL closing idle
connections. Peewee/pymysql's will try to reuse the existing
connection after the MySQL server has already closed it, which will
return an InterfaceError. AFAIK, there isn't a way to actually test
for a a stale connection without actually running a query. Closing the
connection before the transaction forces peewee/pymysql to reopen a
new session to MySQL. This should only applies to non-registry
workers, as the registry workers use a pool by default, and shouldn't
have this issue. Follow-up to 58b06572.
This commit is contained in:
Kenny Lee Sin Cheong
2022-02-28 12:28:10 -05:00
committed by GitHub
parent a3ad25c48a
commit 7cdb88b578

View File

@@ -208,6 +208,16 @@ class DefaultConfig(ImmutableConfig):
@staticmethod
def create_transaction(db):
# This hack is for handling possible MySQL closing idle connections.
# Peewee/pymysql's will try to reuse the existing connection after the MySQL server
# has already closed it, which will return an InterfaceError.
# AFAIK, there isn't a way to actually test for a a stale connection without actually
# running a query. Closing the connection before the transaction forces peewee/pymysql
# to reopen a new session to MySQL. This should only applies to non-registry workers,
# as the registry workers use a pool by default, and shouldn't have this issue.
if type(db.obj).__name__ == "ObservableRetryingMySQLDatabase":
db.close()
return db.transaction()
DB_TRANSACTION_FACTORY = create_transaction