Skip to content

Implement first step of cancellation: Stop all handler when one completes/fails - #204

Open
msirringhaus wants to merge 3 commits into
linux-credentials:mainfrom
msirringhaus:cancellation
Open

Implement first step of cancellation: Stop all handler when one completes/fails#204
msirringhaus wants to merge 3 commits into
linux-credentials:mainfrom
msirringhaus:cancellation

Conversation

@msirringhaus

Copy link
Copy Markdown
Collaborator

Again, based on #135 . Only the last commit is relevant. Will be rebased, once the other PR lands.
Next step would be cancellation events from the UI.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Introduces shared cancellation across credential transports so remaining handlers stop when one completes, fails, or is cancelled.

Changes:

  • Propagates cancellation tokens through USB, NFC, hybrid, and UI handlers.
  • Completes requests on transport success or failure.
  • Adds cancellation-focused tests and dependencies.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
credentialsd/src/dbus/flow_control.rs Stops UI event handling on cancellation.
credentialsd/src/credential_service/mod.rs Coordinates cancellation and request completion.
credentialsd/src/credential_service/usb.rs Adds USB cancellation handling.
credentialsd/src/credential_service/nfc.rs Adds NFC cancellation handling.
credentialsd/src/credential_service/hybrid.rs Adds hybrid cancellation handling.
credentialsd/Cargo.toml Adds cancellation and test dependencies.
Cargo.lock Locks the added dependencies.
Suppressed comments (1)

credentialsd/src/credential_service/mod.rs:1021

  • This assertion is probabilistic: two independent random u32 request IDs can legally be equal, making the test flaky. Either remove this test or inject a deterministic ID generator and test an actual uniqueness contract.
        // IDs should be different (random)
        assert_ne!(
            request_id_1, request_id_2,
            "Sequential requests should (almost certainly) have different IDs"
        );

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +166 to 169
_ = cancellation.cancelled() => {
tracing::debug!("Hybrid handler cancelled, stopping processing");
break Err(Error::Internal("Request cancelled".to_string()));
}
Comment on lines +76 to +78
_ = cancellation.cancelled() => {
tracing::debug!("USB idle polling cancelled");
Err(Error::Internal("Request cancelled".to_string()))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is true, but shouldn't cause any harm, other than some spurious logging. Probably the best solution would be to introduce a Cancelled-error variant and use that everywhere.
This might get a bit more involved, though. @iinuwa do you have any preference as to implementing this right here, or in a follow-up PR?

Comment on lines +69 to +71
_ = cancellation.cancelled() => {
tracing::debug!("NFC idle polling cancelled");
Err(Error::Internal("Request cancelled".to_string()))
Comment thread credentialsd/src/credential_service/usb.rs
Comment on lines +227 to +229
_ = cancellation.cancelled() => {
tracing::debug!("NFC handler cancelled, stopping processing");
break Err(Error::Internal("Request cancelled".to_string()));
}
} => {
state = next_usb_state.unwrap_or_else(UsbStateInternal::Failed);
// Usually, comparing the Discrimimant is enough, but PinNotSet/NeedsPin
Comment thread credentialsd/src/credential_service/mod.rs
Comment thread credentialsd/Cargo.toml Outdated
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