Skip to content

fix(ffi): add methods to make QR login handlers exit cooperatively#6677

Open
Johennes wants to merge 4 commits into
matrix-org:mainfrom
Johennes:johannes/cooperation
Open

fix(ffi): add methods to make QR login handlers exit cooperatively#6677
Johennes wants to merge 4 commits into
matrix-org:mainfrom
Johennes:johannes/cooperation

Conversation

@Johennes

@Johennes Johennes commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

With my Filament hat on: This add new methods on the QR login handlers to make them exit cooperatively by first dropping the updates task and then returning. We've found this necessary when using the React Native FFI bindings in release builds to prevent crashes when the futures are cancelled.

  • I've documented the public API changes in the appropriate changelog files (see Writing changelog entries).
  • This PR was made with the help of AI.

@Johennes Johennes force-pushed the johannes/cooperation branch from 06d5662 to 6d59114 Compare June 19, 2026 15:58
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.86%. Comparing base (7b2b439) to head (551a2b6).
⚠️ Report is 21 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6677      +/-   ##
==========================================
- Coverage   89.86%   89.86%   -0.01%     
==========================================
  Files         396      396              
  Lines      110260   110260              
  Branches   110260   110260              
==========================================
- Hits        99088    99085       -3     
- Misses       7395     7397       +2     
- Partials     3777     3778       +1     

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

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 50 untouched benchmarks


Comparing Johennes:johannes/cooperation (551a2b6) with main (567463d)

Open in CodSpeed

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
@Johennes Johennes force-pushed the johannes/cooperation branch from 6d59114 to a2f3f61 Compare June 19, 2026 17:07
@Johennes Johennes marked this pull request as ready for review June 19, 2026 17:15
@Johennes Johennes requested a review from a team as a code owner June 19, 2026 17:15
@Johennes Johennes requested review from Hywan and removed request for a team June 19, 2026 17:15

@Hywan Hywan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. I think it makes sense but I've added a couple comments.

Would it be possible to move that inside the matrix_sdk crate? First off, it would allow proper testing, and second, it can be useful for Rust users too. Keep in mind the FFI crate is only about bindings, no logic at all.

Comment thread bindings/matrix-sdk-ffi/src/qr_code.rs Outdated

Ok(())
tokio::select! {
biased;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it is biased, why do you want to give priority to login instead of self.cancel.notified()? Cancelling seems more important here, don't you think?

Please add a comment on biased to justify and explain it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. On second thought, I think we don't actually need biasing here. The update from the QR flows depend on user interaction. They should come in sparsely which means biasing shouldn't really make any difference. Have removed it in e9a461d.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

biased would make a difference if two updates come at the same time. So I think we need it! Cancellation must have a higher priority.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, right. Ok, have reverted back to biased and added comments to explain it in 551a2b6.

Comment thread bindings/matrix-sdk-ffi/src/qr_code.rs Outdated
Comment thread bindings/matrix-sdk-ffi/src/qr_code.rs
Johennes added 2 commits June 23, 2026 20:34
…vely

Fix doc comments

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
…vely

Remove biasing

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
@Johennes

Copy link
Copy Markdown
Contributor Author

Would it be possible to move that inside the matrix_sdk crate? First off, it would allow proper testing, and second, it can be useful for Rust users too. Keep in mind the FFI crate is only about bindings, no logic at all.

That would be great but I'm not entirely sure how. The problem only exists because of the progress tasks and those only exist in the FFI crate.

@Johennes Johennes requested a review from Hywan June 23, 2026 18:50
@Hywan

Hywan commented Jun 25, 2026

Copy link
Copy Markdown
Member

The problem only exists because of the progress tasks and those only exist in the FFI crate.

Yes, but there is no interaction between the cancellation and the progress listener. I think it's a safe feature to move into matrix-sdk.

Or, alternatively (I don't want and I don't like this solution but I'm providing an alternative here), add tests in matrix-sdk-ffi for that. But please, consider moving this code (plus adding a test) in matrix-sdk first.

…vely

Revert back to biased and document why its needed

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
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.

2 participants