summary refs log tree commit diff
path: root/synapse/replication/http/send_event.py (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Handle race between persisting an event and un-partial stating a room (#13100)Sean Quah2022-07-051-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Whenever we want to persist an event, we first compute an event context, which includes the state at the event and a flag indicating whether the state is partial. After a lot of processing, we finally try to store the event in the database, which can fail for partial state events when the containing room has been un-partial stated in the meantime. We detect the race as a foreign key constraint failure in the data store layer and turn it into a special `PartialStateConflictError` exception, which makes its way up to the method in which we computed the event context. To make things difficult, the exception needs to cross a replication request: `/fed_send_events` for events coming over federation and `/send_event` for events from clients. We transport the `PartialStateConflictError` as a `409 Conflict` over replication and turn `409`s back into `PartialStateConflictError`s on the worker making the request. All client events go through `EventCreationHandler.handle_new_client_event`, which is called in *a lot* of places. Instead of trying to update all the code which creates client events, we turn the `PartialStateConflictError` into a `429 Too Many Requests` in `EventCreationHandler.handle_new_client_event` and hope that clients take it as a hint to retry their request. On the federation event side, there are 7 places which compute event contexts. 4 of them use outlier event contexts: `FederationEventHandler._auth_and_persist_outliers_inner`, `FederationHandler.do_knock`, `FederationHandler.on_invite_request` and `FederationHandler.do_remotely_reject_invite`. These events won't have the partial state flag, so we do not need to do anything for then. The remaining 3 paths which create events are `FederationEventHandler.process_remote_join`, `FederationEventHandler.on_send_membership_event` and `FederationEventHandler._process_received_pdu`. We can't experience the race in `process_remote_join`, unless we're handling an additional join into a partial state room, which currently blocks, so we make no attempt to handle it correctly. `on_send_membership_event` is only called by `FederationServer._on_send_membership_event`, so we catch the `PartialStateConflictError` there and retry just once. `_process_received_pdu` is called by `on_receive_pdu` for incoming events and `_process_pulled_event` for backfill. The latter should never try to persist partial state events, so we ignore it. We catch the `PartialStateConflictError` in `on_receive_pdu` and retry just once. Refering to the graph of code paths in https://github.com/matrix-org/synapse/issues/12988#issuecomment-1156857648 may make the above make more sense. Signed-off-by: Sean Quah <seanq@matrix.org>
* Rename storage classes (#12913)Erik Johnston2022-05-311-2/+4
|
* Remove `HomeServer.get_datastore()` (#12031)Richard van der Hoff2022-02-231-1/+1
| | | | | | | The presence of this method was confusing, and mostly present for backwards compatibility. Let's get rid of it. Part of #11733
* Add missing type hints to synapse.replication.http. (#11856)Patrick Cloke2022-02-081-17/+27
|
* Add type hints for most `HomeServer` parameters (#11095)Sean Quah2021-10-221-2/+6
|
* Remove redundant "coding: utf-8" lines (#9786)Jonathan de Jong2021-04-141-1/+0
| | | | | | | Part of #9744 Removes all redundant `# -*- coding: utf-8 -*-` lines from files, as python 3 automatically reads source code as utf-8 now. `Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>`
* Prep work for removing `outlier` from `internal_metadata` (#9411)Richard van der Hoff2021-03-171-1/+3
| | | | | | | | | | | | * Populate `internal_metadata.outlier` based on `events` table Rather than relying on `outlier` being in the `internal_metadata` column, populate it based on the `events.outlier` column. * Move `outlier` out of InternalMetadata._dict Ultimately, this will allow us to stop writing it to the database. For now, we have to grandfather it back in so as to maintain compatibility with older versions of Synapse.
* Add ability for access tokens to belong to one user but grant access to ↵Erik Johnston2020-10-291-2/+1
| | | | | | | | | | another user. (#8616) We do it this way round so that only the "owner" can delete the access token (i.e. `/logout/all` by the "owner" also deletes that token, but `/logout/all` by the "target user" doesn't). A future PR will add an API for creating such a token. When the target user and authenticated entity are different the `Processed request` log line will be logged with a: `{@admin:server as @bob:server} ...`. I'm not convinced by that format (especially since it adds spaces in there, making it harder to use `cut -d ' '` to chop off the start of log lines). Suggestions welcome.
* Fix message duplication if something goes wrong after persisting the event ↵Erik Johnston2020-10-131-2/+14
| | | | | (#8476) Should fix #3365.
* Simplify super() calls to Python 3 syntax. (#8344)Patrick Cloke2020-09-181-1/+1
| | | | | | | This converts calls like super(Foo, self) -> super(). Generated with: sed -i "" -Ee 's/super\([^\(]+\)/super()/g' **/*.py
* Convert replication code to async/await. (#7987)Patrick Cloke2020-08-031-5/+2
|
* Convert a synapse.events to async/await. (#7949)Patrick Cloke2020-07-271-1/+1
|
* Add ability to wait for replication streams (#7542)Erik Johnston2020-05-221-2/+2
| | | | | | | The idea here is that if an instance persists an event via the replication HTTP API it can return before we receive that event over replication, which can lead to races where code assumes that persisting an event immediately updates various caches (e.g. current state of the room). Most of Synapse doesn't hit such races, so we don't do the waiting automagically, instead we do so where necessary to avoid unnecessary delays. We may decide to change our minds here if it turns out there are a lot of subtle races going on. People probably want to look at this commit by commit.
* Store room_versions in EventBase objects (#6875)Richard van der Hoff2020-03-051-4/+10
| | | | | | | This is a bit fiddly because it all has to be done on one fell swoop: * Wherever we create a new event, pass in the room version (and check it matches the format version) * When we prune an event, use the room version of the unpruned event to create the pruned version. * When we pass an event over the replication protocol, pass the room version over alongside it, and use it when deserialising the event again.
* Change EventContext to use the Storage class (#6564)Erik Johnston2019-12-201-1/+2
|
* Port replication http server endpoints to async/awaitErik Johnston2019-10-291-4/+3
|
* Remove unnecessary parentheses around return statements (#5931)Andrew Morgan2019-08-301-1/+1
| | | | | Python will return a tuple whether there are parentheses around the returned values or not. I'm just sick of my editor complaining about this all over the place :)
* Replace returnValue with return (#5736)Amber Brown2019-07-231-2/+2
|
* Run Black. (#5482)Amber Brown2019-06-201-7/+6
|
* Replace missed usages of FrozenEventErik Johnston2019-01-251-2/+6
|
* Revert "Require event format version to parse or create events"Erik Johnston2019-01-251-6/+2
|
* Replace missed usages of FrozenEventErik Johnston2019-01-241-2/+6
|
* Rename POST param to METHODErik Johnston2018-08-081-1/+0
|
* Use new helper base class for ReplicationSendEventRestServletErik Johnston2018-07-311-79/+36
|
* Fix missing attributes on workers.Erik Johnston2018-07-231-2/+5
| | | | | This was missed during the transition from attribute to getter for getting state from context.
* run isortAmber Brown2018-07-091-5/+7
|
* Pass around the reactor explicitly (#3385)Amber Brown2018-06-221-3/+3
|
* Refactor ResponseCache usageRichard van der Hoff2018-04-121-12/+6
| | | | | | | | | | | | | | | Adds a `.wrap` method to ResponseCache which wraps up the boilerplate of a (get, set) pair, and then use it throughout the codebase. This will be largely non-functional, but does include the following functional changes: * federation_server.on_context_state_request: drops use of _server_linearizer which looked redundant and could cause incorrect cache misses by yielding between the get and the set. * RoomListHandler.get_remote_public_room_list(): fixes logcontext leaks * the wrap function includes some logging. I'm hoping this won't be too noisy on production.
* Add metrics for ResponseCacheRichard van der Hoff2018-04-101-1/+1
|
* extra_users is actually a list of UserIDsErik Johnston2018-03-131-4/+4
|
* Log in the correct placesErik Johnston2018-03-011-2/+4
|
* Don't do preserve_fn for every requestErik Johnston2018-03-011-1/+2
|
* Add some loggingErik Johnston2018-03-011-0/+2
|
* Make repl send_event idempotent and retry on timeoutsErik Johnston2018-03-011-6/+38
| | | | | | If we treated timeouts as failures on the worker we would attempt to clean up e.g. push actions while the master might still process the event.
* Correctly send ratelimit and extra_users paramsErik Johnston2018-03-011-1/+13
|
* Calculate push actions on workerErik Johnston2018-02-281-1/+1
|
* Don't serialize current state over replicationErik Johnston2018-02-151-2/+2
|
* Don't log errors propogated from send_eventErik Johnston2018-02-151-1/+10
|
* Add replication http endpoint for event sendingErik Johnston2018-02-071-0/+108