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
https://github.com/element-hq/synapse-small-hosts/issues/48
This commit is contained in:
Eric Eastwood 2025-11-03 11:18:56 -06:00 committed by GitHub
parent bc926bd99e
commit e00a411837
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 13 deletions

1
changelog.d/19116.misc Normal file
View File

@ -0,0 +1 @@
Move exception handling up the stack (avoid `exit(1)` in our composable functions).

View File

@ -364,14 +364,11 @@ def start(config: HomeServerConfig) -> None:
# Start the tracer
init_tracer(hs) # noqa
try:
hs.setup()
# Ensure the replication streamer is always started in case we write to any
# streams. Will no-op if no streams can be written to by this worker.
hs.get_replication_streamer()
except Exception as e:
handle_startup_exception(e)
async def start() -> None:
await _base.start(hs)
@ -388,7 +385,10 @@ def start(config: HomeServerConfig) -> None:
def main() -> None:
homeserver_config = load_config(sys.argv[1:])
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
try:
start(homeserver_config)
except Exception as e:
handle_startup_exception(e)
if __name__ == "__main__":

View File

@ -414,10 +414,7 @@ def setup(
# Start the tracer
init_tracer(hs) # noqa
try:
hs.setup()
except Exception as e:
handle_startup_exception(e)
async def _start_when_reactor_running() -> None:
# TODO: Feels like this should be moved somewhere else.
@ -464,7 +461,10 @@ def main() -> None:
# check base requirements
check_requirements()
hs = create_homeserver(homeserver_config)
try:
setup(hs)
except Exception as e:
handle_startup_exception(e)
# redirect stdio to the logs, if configured.
if not hs.config.logging.no_redirect_stdio: