Repository navigation
daemon: Allow clients to cancel requests - #246
Conversation
|
Thanks for this! I will take a look at this next week :) |
iinuwa
left a comment
There was a problem hiding this comment.
Sorry for the delay. I finished reading through the code, and it's looking pretty good! I need to run some tests locally and then I think we can merge this in
iinuwa
left a comment
There was a problem hiding this comment.
Hi @dangerousplay, sorry this took so long to get to!
I quite like the ceremony and cancellation token changes you've made.
The handler interface is supposed to be an internal interface between xdg-desktop-portal and credentialsd; it's also deprecated as we shift architecture in xdg-desktop-portal to share have x-d-p call the backend directly.
So I think I would prefer to export a separate org.freedesktop.handler.portal.experimental.Request interface with a Close() method. That would make it more clear that this is not a normal backend request that clients are supposed to call; they should call the Close() method exported by xdg-desktop-portal instead.
Then on the xdg-desktop-portal side, we should hook into the GObject closed signal on the request object, and call the handler's Close() method in the signal handler.
|
A real-world case for the queued-request cancellation here: testing the browser extension on |
c78ee2e to
5721ec8
Compare
|
Hi @iinuwa, thanks for the review, no worries about the delay ^^ I've pushed the changes:
On the xdg-desktop-portal side (linux-credentials/xdg-desktop-portal#1):
Tested with |
5721ec8 to
84937eb
Compare
xdg-desktop-portal calls org.freedesktop.impl.portal.Request.Close() on the handler when a client closes its request or disconnects, but the daemon never exported such an object, so requests could not be cancelled. Accept an optional `request_handle` object path in the CreateCredential and GetCredential options. For the duration of the ceremony, export an org.freedesktop.handler.portal.experimental.Request object at that path. Close() is only accepted from the connection that started the ceremony; it cancels a token that is passed down to the flow controller, which cancels the request and dismisses the UI. The cancellation does not need the gateway service lock, which is held for the whole ceremony. The method call then returns response code 1 (cancelled).
84937eb to
02262d4
Compare
iinuwa
left a comment
There was a problem hiding this comment.
Thanks! This works well, just a follow-up comment.
| client_cancellation: CancellationToken, | ||
| ) -> Result<CredentialResponse, CredentialServiceError> { | ||
| if client_cancellation.is_cancelled() { | ||
| return Err(CredentialServiceError::Internal( |
There was a problem hiding this comment.
This is a follow-up note, not blocking for this PR: returning Internal here instead of an explicit cancellation error is . Part of the awkwardness is that FlowControlService returns a CredentialServiceError instead of its own error.
Hello I hope you are having a good day ^^
This pull request fixes #90.
When a client closes its
org.freedesktop.portal.Requestor disconnects, xdg-desktop-portal needs a way to tell credentialsd to cancel the ceremony. Until now credentialsd exported nothing it could call, so client cancellation was a no-op and the UI stayed open.This adds an optional
request_handle(o) option to the handler'sCreateCredential/GetCredential. When it is present, credentialsd exportsorg.freedesktop.handler.portal.experimental.Requestat that path for the lifetime of the ceremony. This is an internal interface between xdg-desktop-portal and credentialsd. Clients keep callingClose()on theorg.freedesktop.portal.Requestexported by xdg-desktop-portal.Close()is only accepted from the bus name that issued the handler call (others getAccessDenied).CancellationTokenthat is threaded down to the flow controller. It never takes the gateway mutex, so it cannot deadlock with the running ceremony. A request still queued behind another one is cancelled too.cancel_request()and sendsErrorCancelled, which dismisses the UI through the existing path, and the handler call returns response code 1 (Cancelled)./org/freedesktop/portal/desktop/request/.Without the option, behaviour is unchanged. The matching xdg-desktop-portal change is linux-credentials/xdg-desktop-portal#1. It passes
request_handle = request->idand calls the handler'sClose()from the newXdpRequest::closedsignal.Tested with unit tests (option parsing, response codes, invalid handles), private-bus integration tests (
gio::TestDBus: foreign Close -> AccessDenied, caller Close -> code 1, object removed) and flow-control tests.