Skip to content

Commit e00a411

Browse files
Move exception handling up the stack (avoid exit(1) in our composable functions) (#19116)
Move exception handling up the stack (avoid `exit(1)` in our composable functions) Relevant to Synapse Pro for small hosts as we don't want to exit the entire Python process and affect all homeserver tenants. ### Background As part of Element's plan to support a light form of vhosting (virtual host) (multiple instances of Synapse in the same Python process) (c.f Synapse Pro for small hosts), we're currently diving into the details and implications of running multiple instances of Synapse in the same Python process. "Clean tenant provisioning" tracked internally by element-hq/synapse-small-hosts#48
1 parent bc926bd commit e00a411

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

changelog.d/19116.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move exception handling up the stack (avoid `exit(1)` in our composable functions).

synapse/app/generic_worker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,11 @@ def start(config: HomeServerConfig) -> None:
364364
# Start the tracer
365365
init_tracer(hs) # noqa
366366

367-
try:
368-
hs.setup()
367+
hs.setup()
369368

370-
# Ensure the replication streamer is always started in case we write to any
371-
# streams. Will no-op if no streams can be written to by this worker.
372-
hs.get_replication_streamer()
373-
except Exception as e:
374-
handle_startup_exception(e)
369+
# Ensure the replication streamer is always started in case we write to any
370+
# streams. Will no-op if no streams can be written to by this worker.
371+
hs.get_replication_streamer()
375372

376373
async def start() -> None:
377374
await _base.start(hs)
@@ -388,7 +385,10 @@ async def start() -> None:
388385
def main() -> None:
389386
homeserver_config = load_config(sys.argv[1:])
390387
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
391-
start(homeserver_config)
388+
try:
389+
start(homeserver_config)
390+
except Exception as e:
391+
handle_startup_exception(e)
392392

393393

394394
if __name__ == "__main__":

synapse/app/homeserver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,7 @@ def setup(
414414
# Start the tracer
415415
init_tracer(hs) # noqa
416416

417-
try:
418-
hs.setup()
419-
except Exception as e:
420-
handle_startup_exception(e)
417+
hs.setup()
421418

422419
async def _start_when_reactor_running() -> None:
423420
# TODO: Feels like this should be moved somewhere else.
@@ -464,7 +461,10 @@ def main() -> None:
464461
# check base requirements
465462
check_requirements()
466463
hs = create_homeserver(homeserver_config)
467-
setup(hs)
464+
try:
465+
setup(hs)
466+
except Exception as e:
467+
handle_startup_exception(e)
468468

469469
# redirect stdio to the logs, if configured.
470470
if not hs.config.logging.no_redirect_stdio:

0 commit comments

Comments
 (0)