Repository: matrix-org/synapse

Issue:
v1.9.0 refuses to start with `mau_limit_reserved_threepids` config set
Basically, looks to be a circular dependency during initialisation of `DataStores`, which isn't picked up normally because we cheekily do a `self.hs.get_notifier()` outside of an `__init__`

```
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: --------------------------------------------------------------------------------
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,017 - twisted - 192 - INFO - None- Redirected stdout/stderr to logs
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,018 - root - 257 - WARNING - None- ***** STARTING SERVER *****
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,018 - root - 258 - WARNING - None- Server /opt/synapse/env-py3/lib/python3.7/site-packages/synapse/app/homeserver.py version 1.9.0
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,018 - root - 259 - INFO - None- Server hostname: ...
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,018 - synapse.app.homeserver - 340 - INFO - None- Setting up server
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,018 - synapse.server - 240 - INFO - None- Setting up.
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,046 - synapse.storage.data_stores - 48 - INFO - None- Preparing database 'master'...
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,053 - synapse.storage.prepare_database - 304 - INFO - None- Upgrading schema to v57
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,056 - synapse.storage.data_stores - 58 - INFO - None- Starting 'main' data store
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,090 - twisted - 192 - ERROR - - Traceback (most recent call last):
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,090 - twisted - 192 - ERROR - -   File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,090 - twisted - 192 - ERROR - -     "__main__", mod_spec)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,090 - twisted - 192 - ERROR - -   File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,091 - twisted - 192 - ERROR - -     exec(code, run_globals)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,091 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/app/homeserver.py", line 639, in <module>
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,091 - twisted - 192 - ERROR - -     main()
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,091 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/app/homeserver.py", line 634, in main
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,091 - twisted - 192 - ERROR - -     hs = setup(sys.argv[1:])
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,092 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/app/homeserver.py", line 343, in setup
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,092 - twisted - 192 - ERROR - -     hs.setup()
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,092 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/server.py", line 242, in setup
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,092 - twisted - 192 - ERROR - -     self.datastores = DataStores(self.DATASTORE_CLASS, self)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,092 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/__init__.py", line 65, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,092 - twisted - 192 - ERROR - -     self.main = main_store_class(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,093 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/__init__.py", line 183, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,093 - twisted - 192 - ERROR - -     super(DataStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,093 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/events_bg_updates.py", line 38, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,093 - twisted - 192 - ERROR - -     super(EventsBackgroundUpdatesStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,093 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/roommember.py", line 997, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,093 - twisted - 192 - ERROR - -     super(RoomMemberStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,094 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/room.py", line 879, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,094 - twisted - 192 - ERROR - -     super(RoomStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,094 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/room.py", line 739, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,094 - twisted - 192 - ERROR - -     super(RoomBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,094 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/room.py", line 64, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,095 - twisted - 192 - ERROR - -     super(RoomWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,095 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/registration.py", line 927, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,095 - twisted - 192 - ERROR - -     super(RegistrationStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,095 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/registration.py", line 801, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,095 - twisted - 192 - ERROR - -     super(RegistrationBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,095 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/registration.py", line 41, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,096 - twisted - 192 - ERROR - -     super(RegistrationWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,096 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/stream.py", line 256, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,096 - twisted - 192 - ERROR - -     super(StreamWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,096 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/transactions.py", line 57, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,096 - twisted - 192 - ERROR - -     super(TransactionStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,096 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/state.py", line 336, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,097 - twisted - 192 - ERROR - -     super(StateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,097 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/events.py", line 102, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,097 - twisted - 192 - ERROR - -     super(EventsStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,097 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/state.py", line 61, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,097 - twisted - 192 - ERROR - -     super(StateGroupWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,097 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/event_federation.py", line 460, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,097 - twisted - 192 - ERROR - -     super(EventFederationStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,098 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/media_repository.py", line 38, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,098 - twisted - 192 - ERROR - -     super(MediaRepositoryStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,098 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/media_repository.py", line 22, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,098 - twisted - 192 - ERROR - -     database, db_conn, hs
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,098 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/push_rule.py", line 77, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,098 - twisted - 192 - ERROR - -     super(PushRulesWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,098 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/appservice.py", line 58, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,098 - twisted - 192 - ERROR - -     super(ApplicationServiceWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,099 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/receipts.py", line 326, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,099 - twisted - 192 - ERROR - -     super(ReceiptsStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,099 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/receipts.py", line 43, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,099 - twisted - 192 - ERROR - -     super(ReceiptsWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,099 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/roommember.py", line 59, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,099 - twisted - 192 - ERROR - -     super(RoomMemberWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,099 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/events_worker.py", line 72, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,100 - twisted - 192 - ERROR - -     super(EventsWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,100 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/roommember.py", line 841, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,100 - twisted - 192 - ERROR - -     super(RoomMemberBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,100 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/state.py", line 299, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,100 - twisted - 192 - ERROR - -     super(MainStateBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,100 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/search.py", line 348, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,101 - twisted - 192 - ERROR - -     super(SearchStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,101 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/search.py", line 48, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,101 - twisted - 192 - ERROR - -     super(SearchBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,101 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/account_data.py", line 279, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,101 - twisted - 192 - ERROR - -     super(AccountDataStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,101 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/account_data.py", line 48, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,102 - twisted - 192 - ERROR - -     super(AccountDataWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,102 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/event_push_actions.py", line 616, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,102 - twisted - 192 - ERROR - -     super(EventPushActionsStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,102 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/event_push_actions.py", line 73, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,102 - twisted - 192 - ERROR - -     super(EventPushActionsWorkerStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,102 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/client_ips.py", line 373, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,103 - twisted - 192 - ERROR - -     super(ClientIpStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,103 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/client_ips.py", line 38, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,103 - twisted - 192 - ERROR - -     super(ClientIpBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,103 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/devices.py", line 697, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,103 - twisted - 192 - ERROR - -     super(DeviceStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,103 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/devices.py", line 647, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,104 - twisted - 192 - ERROR - -     super(DeviceBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,104 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/deviceinbox.py", line 246, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,104 - twisted - 192 - ERROR - -     super(DeviceInboxStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,104 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/deviceinbox.py", line 215, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,104 - twisted - 192 - ERROR - -     super(DeviceInboxBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,104 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/user_directory.py", line 554, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,104 - twisted - 192 - ERROR - -     super(UserDirectoryStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,105 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/user_directory.py", line 42, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,105 - twisted - 192 - ERROR - -     super(UserDirectoryBackgroundUpdateStore, self).__init__(database, db_conn, hs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,105 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/monthly_active_users.py", line 106, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,105 - twisted - 192 - ERROR - -     hs.config.mau_limits_reserved_threepids[: self.hs.config.max_mau_value],
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,105 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/database.py", line 378, in new_transaction
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,105 - twisted - 192 - ERROR - -     r = func(cursor, *args, **kwargs)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,105 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/monthly_active_users.py", line 124, in _initialise_reserved_users
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,106 - twisted - 192 - ERROR - -     self.upsert_monthly_active_user_txn(txn, user_id)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,106 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/monthly_active_users.py", line 287, in upsert_monthly_active_user_txn
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,106 - twisted - 192 - ERROR - -     self._invalidate_cache_and_stream(txn, self.get_monthly_active_count, ())
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,106 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/cache.py", line 45, in _invalidate_cache_and_stream
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,106 - twisted - 192 - ERROR - -     self._send_invalidation_to_replication(txn, cache_func.__name__, keys)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,106 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/data_stores/main/cache.py", line 112, in _send_invalidation_to_replication
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,107 - twisted - 192 - ERROR - -     txn.call_after(self.hs.get_notifier().on_new_replication_data)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,107 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/server.py", line 562, in _get
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,107 - twisted - 192 - ERROR - -     dep = builder()
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,107 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/server.py", line 304, in build_notifier
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,107 - twisted - 192 - ERROR - -     return Notifier(self)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,107 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/notifier.py", line 164, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,107 - twisted - 192 - ERROR - -     self.storage = hs.get_storage()
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,108 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/server.py", line 562, in _get
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,108 - twisted - 192 - ERROR - -     dep = builder()
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,108 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/server.py", line 531, in build_storage
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,108 - twisted - 192 - ERROR - -     return Storage(self, self.datastores)
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,108 - twisted - 192 - ERROR - -   File "/opt/synapse/env-py3/lib/python3.7/site-packages/synapse/storage/__init__.py", line 47, in __init__
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,108 - twisted - 192 - ERROR - -     self.main = stores.main
Jan 28 11:24:19 ip-10-1-2-181 matrix_synapse[19453]: 2020-01-28 11:24:19,109 - twisted - 192 - ERROR - - AttributeError: 'NoneType' object has no attribute 'main'
```


Discussion:

Resolving patch:
diff --git a/synapse/storage/data_stores/main/monthly_active_users.py b/synapse/storage/data_stores/main/monthly_active_users.py
--- a/synapse/storage/data_stores/main/monthly_active_users.py
+++ b/synapse/storage/data_stores/main/monthly_active_users.py
@@ -121,7 +121,13 @@ def _initialise_reserved_users(self, txn, threepids):
             if user_id:
                 is_support = self.is_support_user_txn(txn, user_id)
                 if not is_support:
-                    self.upsert_monthly_active_user_txn(txn, user_id)
+                    # We do this manually here to avoid hitting #6791
+                    self.db.simple_upsert_txn(
+                        txn,
+                        table="monthly_active_users",
+                        keyvalues={"user_id": user_id},
+                        values={"timestamp": int(self._clock.time_msec())},
+                    )
             else:
                 logger.warning("mau limit reserved threepid %s not found in db" % tp)
 


Test patch: