element-hq / element-hq/synapse

Create a way for modules to run async code at startup

Open
#12,433 0 comments 0 reactions 0 assignees View on GitHub
A-Modules S-Minor T-Enhancement
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#12433](https://github.com/matrix-org/synapse/issues/12433).

---

Some modules might want to run some async code at startup, to e.g. set up their database tables before any code accessing this table can be called (to avoid races). Currently the only way to do so is to run that code inside `run_in_background`, which can be prone to races.

It looks to me like it would be simple enough to add an async `setup` callback somewhere around [here](https://github.com/matrix-org/synapse/blob/e24ff8ebe3d4119d377355402245947f7de61c00/synapse/app/_base.py#L434-L444) that allows modules to run async code before e.g. listeners start.

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.