Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): Ensure a gap has been inserted before removing it #4490

Merged
merged 3 commits into from
Jan 9, 2025

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Jan 8, 2025

This patch fixes a bug where the code assumes a gap has been inserted, and thus, is always present. But this isn't the case. If prev_batch is None, a gap is not inserted, and so we cannot remove it. This patch checks that prev_batch is Some(_), which means the invariant is correct, and the code can remove the gap.

This patch fixes a bug where the code assumes a gap has been inserted,
and thus, is always present. But this isn't the case. If `prev_batch`
is `None`, a gap is not inserted, and so we cannot remove it. This patch
checks that `prev_batch` is `Some(_)`, which means the invariant is
correct, and the code can remove the gap.
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.32%. Comparing base (62567ca) to head (e0c9b7a).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4490      +/-   ##
==========================================
+ Coverage   85.31%   85.32%   +0.01%     
==========================================
  Files         284      284              
  Lines       31741    31745       +4     
==========================================
+ Hits        27080    27087       +7     
+ Misses       4661     4658       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BillCarsonFr
Copy link
Member

Should fix this then element-hq/element-x-ios#3648?

@bnjbvr
Copy link
Member

bnjbvr commented Jan 9, 2025

Should fix this then element-hq/element-x-ios#3648?

To wit: usually those issues are marked as fixed when the app upstreams the SDK, so we don't have the SDK close EX apps issues.

@bnjbvr bnjbvr marked this pull request as ready for review January 9, 2025 10:41
@bnjbvr bnjbvr requested a review from a team as a code owner January 9, 2025 10:41
@bnjbvr bnjbvr requested review from bnjbvr and removed request for a team January 9, 2025 10:41
Comment on lines +448 to +450
let gap = as_variant::as_variant!(c.content(), ChunkContent::Gap)?;
(gap.prev_token == *prev_token).then_some(c.identifier())
Copy link
Member

@bnjbvr bnjbvr Jan 9, 2025

Choose a reason for hiding this comment

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

Since we're touching this code, I also made the check more precise: instead of "give me the previous gap, whatever it is", this is now "give me the previous gap with the matching prev-batch token". This would have made the bug much more frequent.

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer a named function for the code inside find_map because it took me quite a while to figure out what this was doing, but I won't insist on it, and I'm happy for the change to come later if you like the idea.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! added a small code comment above this line, expliciting what it does 👍

@bnjbvr bnjbvr requested review from a team and andybalaam and removed request for a team January 9, 2025 10:43
Copy link
Member

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

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

Looks good, one optional comment.

Comment on lines +448 to +450
let gap = as_variant::as_variant!(c.content(), ChunkContent::Gap)?;
(gap.prev_token == *prev_token).then_some(c.identifier())
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer a named function for the code inside find_map because it took me quite a while to figure out what this was doing, but I won't insist on it, and I'm happy for the change to come later if you like the idea.

@bnjbvr bnjbvr force-pushed the fix-sdk-event-cache-panic-with-gaps branch from d29bf7c to e0c9b7a Compare January 9, 2025 10:56
@bnjbvr bnjbvr enabled auto-merge (rebase) January 9, 2025 10:57
@bnjbvr bnjbvr merged commit 9e97ed3 into matrix-org:main Jan 9, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants