Skip to content

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

Open
Johennes wants to merge 3 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 3 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.87%. Comparing base (7b2b439) to head (e9a461d).
⚠️ Report is 5 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.87%           
=======================================
  Files         396      396           
  Lines      110260   110260           
  Branches   110260   110260           
=======================================
+ Hits        99088    99098   +10     
+ Misses       7395     7391    -4     
+ Partials     3777     3771    -6     

☔ 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 (e9a461d) with main (e8673e4)

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
pub struct LoginWithQrCodeHandler {
oauth: OAuth,
oauth_configuration: OAuthConfiguration,
/// Request a the handler to abort cooperatively. This will make the handler

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.

“a the”?

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.

Sorry. 🤦‍♂️ Fixed in f8a8539.

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.

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

Ok(())
/// Request a the handler to abort cooperatively. This will make the handler

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.

“a the”?

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.

Fixed in f8a8539.

_ = self.cancel.notified() => {
// Stop forwarding progress to the foreign callback before tearing
// down the handler.
drop(progress_task);

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.

Don't you want to emit a progress (on progress_listener) to stay it's been cancelled?

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.

I think not. The existing pattern with the handler is that any errors are returned via the method's result rather than the update listener. That's why the state enums don't contain any variants for errors or cancellation. So I think just returning an error fits in with the pattern (though you might of course question the pattern itself).

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
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