Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit c2d4467

Browse files
authored
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
1 parent 41a3899 commit c2d4467

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

changelog.d/8726.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where Synapse would not recover after losing connection to the database.

synapse/storage/database.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,18 @@ def make_pool(
8888
"""Get the connection pool for the database.
8989
"""
9090

91+
# By default enable `cp_reconnect`. We need to fiddle with db_args in case
92+
# someone has explicitly set `cp_reconnect`.
93+
db_args = dict(db_config.config.get("args", {}))
94+
db_args.setdefault("cp_reconnect", True)
95+
9196
return adbapi.ConnectionPool(
9297
db_config.config["name"],
9398
cp_reactor=reactor,
9499
cp_openfun=lambda conn: engine.on_new_connection(
95100
LoggingDatabaseConnection(conn, engine, "on_new_connection")
96101
),
97-
**db_config.config.get("args", {}),
102+
**db_args,
98103
)
99104

100105

0 commit comments

Comments
 (0)