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

Commit 70cbb1a

Browse files
H-Shayreivilibre
andauthored
Don't start Synapse master process if worker_app is set (#11416)
* Add check to catch syanpse master process starting when workers are configured * add test to verify that starting master process with worker config raises error * newsfragment * specify config.worker.worker_app in check * update test * report specific config option that triggered the error Co-authored-by: reivilibre <[email protected]> * clarify error message Co-authored-by: reivilibre <[email protected]> Co-authored-by: reivilibre <[email protected]>
1 parent 42bf020 commit 70cbb1a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

changelog.d/11416.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a check to ensure that users cannot start the Synapse master process when `worker_app` is set.

synapse/app/homeserver.py

+7
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ def setup(config_options: List[str]) -> SynapseHomeServer:
358358
# generating config files and shouldn't try to continue.
359359
sys.exit(0)
360360

361+
if config.worker.worker_app:
362+
raise ConfigError(
363+
"You have specified `worker_app` in the config but are attempting to start a non-worker "
364+
"instance. Please use `python -m synapse.app.generic_worker` instead (or remove the option if this is the main process)."
365+
)
366+
sys.exit(1)
367+
361368
events.USE_FROZEN_DICTS = config.server.use_frozen_dicts
362369
synapse.util.caches.TRACK_MEMORY_USAGE = config.caches.track_memory_usage
363370

tests/app/test_homeserver_start.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 The Matrix.org Foundation C.I.C.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import synapse.app.homeserver
16+
from synapse.config._base import ConfigError
17+
18+
from tests.config.utils import ConfigFileTestCase
19+
20+
21+
class HomeserverAppStartTestCase(ConfigFileTestCase):
22+
def test_wrong_start_caught(self):
23+
# Generate a config with a worker_app
24+
self.generate_config()
25+
# Add a blank line as otherwise the next addition ends up on a line with a comment
26+
self.add_lines_to_config([" "])
27+
self.add_lines_to_config(["worker_app: test_worker_app"])
28+
29+
# Ensure that starting master process with worker config raises an exception
30+
with self.assertRaises(ConfigError):
31+
synapse.app.homeserver.setup(["-c", self.config_file])

0 commit comments

Comments
 (0)