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

Fix race in sync when joining room #2944

Merged
merged 3 commits into from
Mar 7, 2018
Merged

Conversation

erikjohnston
Copy link
Member

The race happens when the user joins a room at the same time as doing a
sync. We fetch the current token and then get the rooms the user is in.
If the join happens after the current token, but before we get the rooms
we end up sending down a partial room entry in the sync.

This is fixed by looking at the stream ordering of the membership
returned by get_rooms_for_user, and handling the case when that stream
ordering is after the current token.

joined_room_ids.add(room_id)
continue

logger.info("SH joined_room_ids membership after current token")
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, forgot about this debug logging. Perhaps we want to keep something like it here? WDYT?

joined_room_ids.add(room_id)
continue

logger.info("SH joined_room_ids membership after current token")
Copy link
Member

Choose a reason for hiding this comment

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

SH?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, sorry, as I mentioned in a comment this was debug logging I forgot to remove, (SH was just a way for me to search in logs for). Do you think it'd be useful to keep this log line? This case should be hit rarely.

# If the membership's stream ordering is after the given stream
# ordering, we need to go and work out if the user was in the room
# before.
for room_id, membeship_stream_ordering in joined_rooms:
Copy link
Member

Choose a reason for hiding this comment

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

membe

user_id = sync_config.user.to_string()
app_service = self.store.get_app_service_by_user_id(user_id)
if app_service:
rooms = yield self.store.get_app_service_rooms(app_service)
Copy link
Member

Choose a reason for hiding this comment

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

do we not need to worry about the same thing here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeeeeeeeeeeeeeeeeeees, though I really want to burn this code path with fire since its so inefficient and nothing should really be using it. Looking at the code again it actually may not be as bad to fix as I initially thought

Copy link
Member Author

Choose a reason for hiding this comment

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

(I'll do that)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, though I think this code paths is actually broken, as it tries to instantiate RoomsForUser with too few arguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

i.e., I'm wondering if we can just stub it out with a NotImplementedError or something

@richvdh richvdh assigned erikjohnston and unassigned richvdh Mar 5, 2018
The race happens when the user joins a room at the same time as doing a
sync. We fetch the current token and then get the rooms the user is in.
If the join happens after the current token, but before we get the rooms
we end up sending down a partial room entry in the sync.

This is fixed by looking at the stream ordering of the membership
returned by get_rooms_for_user, and handling the case when that stream
ordering is after the current token.
@erikjohnston erikjohnston force-pushed the erikj/fix_sync_race branch from 6629b8e to a56d54d Compare March 7, 2018 11:55
@erikjohnston
Copy link
Member Author

(Sorry for rebasing, I did it on autopilot forgetting you'd already reviewed)

@erikjohnston erikjohnston assigned richvdh and unassigned erikjohnston Mar 7, 2018
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

@richvdh richvdh assigned erikjohnston and unassigned richvdh Mar 7, 2018
@erikjohnston erikjohnston merged commit 735fd87 into develop Mar 7, 2018
@erikjohnston erikjohnston deleted the erikj/fix_sync_race branch March 22, 2018 12:59
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.

2 participants