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

Commit

Permalink
Close the database connection we create during startup (#8131)
Browse files Browse the repository at this point in the history
... otherwise it gets leaked.
  • Loading branch information
richvdh authored Aug 19, 2020
1 parent c9c544c commit 12aebdf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/8131.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which could cause a leaked postgres connection if synapse was set to daemonize.
11 changes: 10 additions & 1 deletion synapse/storage/databases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,21 @@ def __init__(self, main_store_class, hs):

logger.info("Database %r prepared", db_name)

# Closing the context manager doesn't close the connection.
# psycopg will close the connection when the object gets GCed, but *only*
# if the PID is the same as when the connection was opened [1], and
# it may not be if we fork in the meantime.
#
# [1]: https://github.com/psycopg/psycopg2/blob/2_8_5/psycopg/connection_type.c#L1378

db_conn.close()

# Sanity check that we have actually configured all the required stores.
if not main:
raise Exception("No 'main' data store configured")

if not state:
raise Exception("No 'main' data store configured")
raise Exception("No 'state' data store configured")

# We use local variables here to ensure that the databases do not have
# optional types.
Expand Down

0 comments on commit 12aebdf

Please sign in to comment.