Skip to content

Commit

Permalink
database: handle nested transaaction when trying to close before tran…
Browse files Browse the repository at this point in the history
…saction (PROJQUAY-3303) (#1157)

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

This reverts commit 7cdb88b.

* database: handle nested transaaction when trying to close before transaction (PROJQUAY-3303)

Handle nested transaction when trying to catch InterfaceError from
pymsql/mysql's idle connections. If the connection is already in a
transaction, then we'll assume it doesn't need to be closed
beforehand, as it's probably in-use, and unlikely to be cleaned up.
  • Loading branch information
kleesc authored Mar 1, 2022
1 parent 7162be3 commit 24b3c15
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ def create_transaction(db):
# 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()
try:
db.close()
except:
# Only try to close the connection. Otherwise closing connections in a nested transaction
# will return an OperationalError. In that case, we can just continue with the normal flow,
# as we know the connection is likely in use and not stale.
pass

return db.transaction()

Expand Down

0 comments on commit 24b3c15

Please sign in to comment.