Enable reconnection in DB pool (#8726)

`adbapi.ConnectionPool` let's you turn on auto reconnect of DB connections. This is off by default.
As far as I can tell if its not enabled dead connections never get removed from the pool.

Maybe helps #8574
This commit is contained in:
Erik Johnston 2020-11-12 14:26:24 +00:00 committed by GitHub
parent 41a389934e
commit c2d4467cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

1
changelog.d/8726.bugfix Normal file
View File

@ -0,0 +1 @@
Fix bug where Synapse would not recover after losing connection to the database.

View File

@ -88,13 +88,18 @@ def make_pool(
"""Get the connection pool for the database.
"""
# By default enable `cp_reconnect`. We need to fiddle with db_args in case
# someone has explicitly set `cp_reconnect`.
db_args = dict(db_config.config.get("args", {}))
db_args.setdefault("cp_reconnect", True)
return adbapi.ConnectionPool(
db_config.config["name"],
cp_reactor=reactor,
cp_openfun=lambda conn: engine.on_new_connection(
LoggingDatabaseConnection(conn, engine, "on_new_connection")
),
**db_config.config.get("args", {}),
**db_args,
)