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

Commit

Permalink
Merge commit '12aebdfa5' into anoa/dinsic_release_1_21_x
Browse files Browse the repository at this point in the history
* commit '12aebdfa5':
  Close the database connection we create during startup (#8131)
  • Loading branch information
anoadragon453 committed Oct 20, 2020
2 parents 687d30b + 12aebdf commit ac743d6
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 ac743d6

Please sign in to comment.