element-hq / element-hq/synapse

Synapse tries to use `run_as_background_process` during homeserver shutdown process (which fails)

Open
#19,182 0 comments 0 reactions 0 assignees View on GitHub
A-Shutdown O-Uncommon S-Minor T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

Synapse tries to use [`run_as_background_process(...)`](https://github.com/element-hq/synapse/blob/408a05ebbc70f94cb31e29ebac2d24df8363dfd6/synapse/server.py#L362-L403) during homeserver shutdown process but since we prevent new background processes from starting after someone calls `hs.shutdown()`, those just end up failing and we log the failure:

```
ERROR - Error calling shutdown async handler: Cannot start background process. HomeServer has been shutdown
```

### Dev notes

This was introduced in https://github.com/element-hq/synapse/pull/18828

Example usage to register a new `_async_shutdown_handlers` (notice that it's using `@wrap_as_background_process`):

https://github.com/element-hq/synapse/blob/408a05ebbc70f94cb31e29ebac2d24df8363dfd6/synapse/handlers/presence.py#L533-L544

In `hs.shutdown()`, we try to call of the `_async_shutdown_handlers`:

https://github.com/element-hq/synapse/blob/408a05ebbc70f94cb31e29ebac2d24df8363dfd6/synapse/server.py#L490-L496

### Reproduction

This is even reproducible in our tests but because we just log, the test doesn't fail.

```
SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.app.test_homeserver_shutdown.HomeserverCleanShutdownTestCase.test_clean_homeserver_shutdown
```

`_trial_temp/test.log`
```
ERROR - Error calling shutdown async handler: Cannot start background process. HomeServer has been shutdown
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.