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

Disable federation when using SQLite by default #5078

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c58538d
Add config for disabling/enabling federation when using SQLite
babolivier Apr 18, 2019
6a72d7a
Deny federation traffic if config says so
babolivier Apr 18, 2019
8050fa4
Merge branch 'develop' into babolivier/sqlite_federation
babolivier Apr 18, 2019
56ac502
fix
babolivier Apr 18, 2019
415a3fe
Changelog
babolivier Apr 18, 2019
051e8b5
fix
babolivier Apr 18, 2019
7fd865e
Sample config
babolivier Apr 18, 2019
6629da6
Fix unit tests
babolivier Apr 18, 2019
50c2dd6
Lint
babolivier Apr 18, 2019
e751bb0
pop instead of get
babolivier Apr 18, 2019
7911334
i give up
babolivier Apr 18, 2019
e44b275
sample conf
babolivier Apr 18, 2019
25de64f
fix
babolivier Apr 18, 2019
48985f9
Update synapse/config/database.py
aaronraimist Apr 18, 2019
4138b06
Update synapse/config/database.py
aaronraimist Apr 18, 2019
288b555
arrrrgh scaaary
babolivier Apr 18, 2019
131df58
sample conf
babolivier Apr 18, 2019
c5956d4
Update synapse/config/database.py
richvdh Apr 25, 2019
35e7b60
Merge branch 'develop' into babolivier/sqlite_federation
babolivier Apr 25, 2019
66fee87
review
babolivier Apr 25, 2019
94c4bd3
Merge branch 'babolivier/sqlite_federation' of github.com:matrix-org/…
babolivier Apr 25, 2019
0a8cd10
Merge branch 'develop' into babolivier/sqlite_federation
babolivier Apr 25, 2019
2e04f2c
o no
babolivier Apr 25, 2019
a32cd95
config
babolivier Apr 25, 2019
97e27a5
Reverting undeeded change
babolivier Apr 26, 2019
209c777
Fix test config
babolivier Apr 26, 2019
637e82c
Update doc
babolivier Apr 26, 2019
8216106
Add test case
babolivier Apr 26, 2019
72f80c0
Update other doc
babolivier Apr 26, 2019
235136a
lint
babolivier Apr 26, 2019
3a36244
Update synapse/config/server.py
richvdh May 1, 2019
1aef88d
Incorporate review
babolivier May 1, 2019
d1482a8
Merge branch 'babolivier/sqlite_federation' of github.com:matrix-org/…
babolivier May 1, 2019
841b644
Use a more sensible way to get database settings
babolivier May 1, 2019
972b54a
Sample config
babolivier May 3, 2019
13b853a
Merge branch 'develop' into babolivier/sqlite_federation
babolivier May 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5078.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable federation when using SQLite by default.
15 changes: 15 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,21 @@ acme:
## Database ##

database:
# Using SQLite induces a severe degradation in performances,
# especially when using federation. SQLite should only be used for
# personal testing and production instances should use PostgreSQL
# instead. You can find documentation on setting up PostgreSQL with
# Synapse here:
# https://github.com/matrix-org/synapse/blob/master/docs/postgres.rst
#
# If you want to use federation with SQLite regardless, you can
# uncomment the line below, but be aware that it can make Synapse
# very laggy and malfunctioning, especially when joining large
# rooms. This option defaults to False when using SQLite and True
# otherwise.
#
#enable_federation = True

# The database engine name
name: "sqlite3"
# Arguments to pass to the engine
Expand Down
23 changes: 22 additions & 1 deletion synapse/config/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ def read_config(self, config):

name = self.database_config.get("name", None)
if name == "psycopg2":
pass
self.database_enable_federation = self.database_config.get(
"enable_federation", True,
)
elif name == "sqlite3":
self.database_config.setdefault("args", {}).update({
"cp_min": 1,
"cp_max": 1,
"check_same_thread": False,
})

self.database_enable_federation = self.database_config.get(
"enable_federation", False,
)
else:
raise RuntimeError("Unsupported database type '%s'" % (name,))

Expand All @@ -52,6 +58,21 @@ def default_config(self, data_dir_path, **kwargs):
## Database ##

database:
# Using SQLite induces a severe degradation in performances,
babolivier marked this conversation as resolved.
Show resolved Hide resolved
# especially when using federation. SQLite should only be used for
babolivier marked this conversation as resolved.
Show resolved Hide resolved
# personal testing and production instances should use PostgreSQL
babolivier marked this conversation as resolved.
Show resolved Hide resolved
# instead. You can find documentation on setting up PostgreSQL with
# Synapse here:
# https://github.com/matrix-org/synapse/blob/master/docs/postgres.rst
#
# If you want to use federation with SQLite regardless, you can
# uncomment the line below, but be aware that it can make Synapse
# very laggy and malfunctioning, especially when joining large
babolivier marked this conversation as resolved.
Show resolved Hide resolved
# rooms. This option defaults to False when using SQLite and True
# otherwise.
#
#enable_federation = True

# The database engine name
name: "sqlite3"
# Arguments to pass to the engine
Expand Down
3 changes: 2 additions & 1 deletion synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def __init__(self, hs):
self.server_name = hs.hostname
self.store = hs.get_datastore()
self.federation_domain_whitelist = hs.config.federation_domain_whitelist
self.database_enable_federation = hs.config.database_enable_federation

# A method just so we can pass 'self' as the authenticator to the Servlets
@defer.inlineCallbacks
Expand Down Expand Up @@ -130,7 +131,7 @@ def authenticate_request(self, request, content):
if (
self.federation_domain_whitelist is not None and
origin not in self.federation_domain_whitelist
):
) or not self.database_enable_federation:
raise FederationDeniedError(origin)

if not json_request["signatures"]:
Expand Down
2 changes: 1 addition & 1 deletion synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _send_request(
if (
self.hs.config.federation_domain_whitelist is not None and
request.destination not in self.hs.config.federation_domain_whitelist
):
) or not self.hs.config.database_enable_federation:
raise FederationDeniedError(request.destination)

limiter = yield synapse.util.retryutils.get_retry_limiter(
Expand Down
5 changes: 3 additions & 2 deletions synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self, hs):
self.recently_accessed_locals = set()

self.federation_domain_whitelist = hs.config.federation_domain_whitelist
self.database_enable_federation = hs.config.database_enable_federation

# List of StorageProviders where we should search for media and
# potentially upload to.
Expand Down Expand Up @@ -234,7 +235,7 @@ def get_remote_media(self, request, server_name, media_id, name):
if (
self.federation_domain_whitelist is not None and
server_name not in self.federation_domain_whitelist
):
) or not self.database_enable_federation:
raise FederationDeniedError(server_name)

self.mark_recently_accessed(server_name, media_id)
Expand Down Expand Up @@ -274,7 +275,7 @@ def get_remote_media_info(self, server_name, media_id):
if (
self.federation_domain_whitelist is not None and
server_name not in self.federation_domain_whitelist
):
) or not self.database_enable_federation:
raise FederationDeniedError(server_name)

# We linearize here to ensure that we don't try and download remote
Expand Down
8 changes: 7 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def default_config(name):
# background, which upsets the test runner.
config.update_user_directory = False

config.database_enable_federation = True
babolivier marked this conversation as resolved.
Show resolved Hide resolved

return config


Expand Down Expand Up @@ -244,7 +246,11 @@ def setup_test_homeserver(
else:
config.database_config = {
"name": "sqlite3",
"args": {"database": ":memory:", "cp_min": 1, "cp_max": 1},
"args": {
"database": ":memory:",
"cp_min": 1,
"cp_max": 1,
},
}

db_engine = create_engine(config.database_config)
Expand Down