Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Conversation

anoadragon453
Copy link
Member

@anoadragon453 anoadragon453 commented Oct 20, 2021

We typically figure out which EDUs to send to application services based the last stream token that appservice successfully received. This is true for read receipts and user presence, however for typing we always just send the last typing event. This process is started whenever a new read receipt, presence update or typing event is processed by the server. In that case, notify_interested_services_ephemeral will be called with the new event and its stream token (so we can check whether we need to send any other events to the appservice may have missed).

With all that in mind, I believe I've found a bug in the implementation. If a RoomStreamToken object was provided as the new_token argument to _notify_app_services_ephemeral, new_token would be set to None, before then being passed to notify_interested_services_ephemeral and then _notify_interested_services_ephemeral. The commit that introduced this change (559974f) was intended to prevent mypy from failing. (_)notify_app_services_ephemeral was also configured to allow new_token to be an Optional[int] as a result.

However, if None is provided, _notify_app_services_ephemeral will end up passing None to set_type_stream_id_for_appservice, which will clear each appservice's stream token for the given stream_key. Doing so means that we send all presence or read receipt data from a None stream token up until the latest token(!). This seems like a bug to do every time we have a RoomStreamToken rather than an int. Actually, all stream keys that are passed to _notify_interested_services_ephemeral (typing_key, receipt_key, presence_key) are passing int values for new_token, so the buggy code would have never fired anyways.

Regardless, I propose converting the RoomStreamToken to an int using RoomStreamToken.stream (I think this is the right way to convert it. RoomStreamToken can end up being a vector clock when you have multiple event persister workers; in this case stream will be the minimum stream token amongst all workers... which I think is fine... maybe? This appears to be correct, we do it elsewhere as well.)

This may relate to the large bursts of EDU traffic Synapse is sending to AS's ala #10836. See above. The code should not have actually resulted in broken behaviour.

…meral

Previously, if a RoomStreamToken object were provided, new_token would
be set to `None`. In the same changeset, which was intended to prevent
mypy from failing, `_notify_app_services_ephemeral` was configured
to allow `new_token` to be an Optional[int]
(559974f).

However, if `None` is provided, `_notify_app_services_ephemeral` will
end up passing `None` to `set_type_stream_id_for_appservice`, which will
effectively clear each appservice's stream token for the given
`stream_key`. This seems like a bug to do every time we have a
RoomStreamToken rather than an int.

Instead, I'm converting the RoomStreamToken to an int using
RoomStreamToken.stream. I think this is the right way to convert to an
int. If RoomStreamToken this ends up being a vector clock, `stream` will
be the minimum stream token amongst all workers... which I think is fine?
@anoadragon453 anoadragon453 changed the title Fix providing a RoomStreamToken instance to _notify_app_services_ephemeral Fix providing a RoomStreamToken instance to _notify_app_services_ephemeral Oct 20, 2021
@anoadragon453 anoadragon453 requested a review from a team October 20, 2021 15:40
@anoadragon453 anoadragon453 marked this pull request as ready for review October 20, 2021 15:40
@DMRobertson DMRobertson self-assigned this Oct 21, 2021
Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look sensible. CI is happy.

Instead, I propose converting the RoomStreamToken to an int using RoomStreamToken.stream (I think this is the right way to convert it. RoomStreamToken can end up being a vector clock when you have multiple event persister workers; in this case stream will be the minimum stream token amongst all workers... which I think is fine... maybe?)

Not sure on this. One for @erikjohnston or @richvdh ?

@DMRobertson DMRobertson requested a review from a team October 21, 2021 12:48
@DMRobertson DMRobertson removed their assignment Oct 21, 2021
While searching around for all types that were eventually passed into on_new_event,
I found a couple methods which didn't specify the type they returned. So this commit
adds return type hints for those methods.

I didn't do any other arguments as I plan to type-hint those files later anyways.
…instead

This is a small effort to reduce the layers of methods we have here.

Also, I've opted to continue converting the RoomStreamToken to an int,
but only for when tracking stream tokens of EDUs. As stated in the
comment, this shouldn't have any gaps as long as we *always* convert to
minimum value.
@anoadragon453 anoadragon453 requested a review from richvdh October 26, 2021 16:03
@erikjohnston erikjohnston added the X-Awaiting-Changes A contributed PR which needs changes and re-review before it can be merged label Nov 1, 2021
@anoadragon453 anoadragon453 force-pushed the anoa/e2e_as_room_stream_token branch from b70ceca to 4414e22 Compare November 1, 2021 14:45
@anoadragon453 anoadragon453 requested a review from richvdh November 1, 2021 14:47
@anoadragon453 anoadragon453 removed the X-Awaiting-Changes A contributed PR which needs changes and re-review before it can be merged label Nov 1, 2021
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Co-authored-by: Richard van der Hoff <[email protected]>
@anoadragon453 anoadragon453 enabled auto-merge (squash) November 2, 2021 10:13
@anoadragon453 anoadragon453 merged commit c9c3aea into develop Nov 2, 2021
@anoadragon453 anoadragon453 deleted the anoa/e2e_as_room_stream_token branch November 2, 2021 10:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants