Skip to content

daemon: Allow clients to cancel requests - #246

Open
dangerousplay wants to merge 1 commit into
linux-credentials:mainfrom
dangerousplay:handler-request-close
Open

dangerousplay wants to merge 1 commit into
linux-credentials:mainfrom
dangerousplay:handler-request-close

Conversation

@dangerousplay

@dangerousplay dangerousplay commented Oct 17, 2026 •

Copy link
Copy Markdown

Hello I hope you are having a good day ^^

This pull request fixes #90.

xdg-desktop-portal creates an org.freedesktop.impl.portal.Request proxy for every
Credential request at request->id on the handler's bus name and calls Close() on it
when the client closes its org.freedesktop.portal.Request or disconnects. credentialsd
never learned that path and never exported the object, so client cancellation was a no-op
and the UI stayed open.

This adds an optional request_handle (o) option to the handler's CreateCredential /
GetCredential. When present, credentialsd exports org.freedesktop.impl.portal.Request
at that path for the lifetime of the ceremony:

  • Close() is only accepted from the bus name that issued the handler call
    (others get AccessDenied).
  • It cancels a CancellationToken that 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.
  • The ceremony then calls cancel_request() and sends ErrorCancelled, which dismisses the UI
    through the existing path, and the handler call returns response code 1 (Cancelled).
  • The object is removed when the ceremony ends, whatever the outcome.
  • The path must live under /org/freedesktop/portal/desktop/request/.

Without the option, behaviour is unchanged. The matching one-line xdg-desktop-portal change
(passing request_handle = request->id) is in linux-credentials/xdg-desktop-portal#1.

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), flow-control tests, and end to end from a WebKitGTK client
(AbortController.abort() -> Request.Close -> ceremony cancelled, UI dismissed).

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.impl.portal.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).

Fixes linux-credentials#90
@iinuwa

iinuwa commented Oct 22, 2026

Copy link
Copy Markdown
Member

Thanks for this! I will take a look at this next week :)

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.

Allow clients to cancel requests

2 participants