Skip to content

daemon: Cancel a request when its caller disconnects - #278

Merged
iinuwa merged 1 commit into
linux-credentials:mainfrom
kpanuragh:cancel-on-disconnect
Nov 20, 2026
Merged

iinuwa merged 1 commit into
linux-credentials:mainfrom
kpanuragh:cancel-on-disconnect

Conversation

@kpanuragh

Copy link
Copy Markdown
Contributor

Fixes #274.

#246 lets a client cancel a request with Close(), but a request whose caller leaves the bus unexpectedly, e.g. because it crashed, stays open until the user dismisses the UI.

run_ceremony now watches the caller's unique name for as long as the ceremony runs and cancels the request once the name has no owner:

  • It subscribes to NameOwnerChanged for the caller and then checks NameHasOwner, so a caller that left before the watch was set up is caught too.
  • It works with and without a request handle. A request that is still queued behind another one is cancelled as well, as with Close().
  • The watch is dropped, and its match rule removed, when the ceremony ends.
  • If the watch can't be set up, the failure is logged and the request goes on as before.

Scope

In the portal setup the daemon's caller is xdg-desktop-portal, not the app. When the app goes away, the portal already closes the handler request (linux-credentials/xdg-desktop-portal#1 → Close() from #246). So this change covers:

  • xdg-desktop-portal itself going away mid-request;
  • callers that talk to the daemon directly.

It does not cancel a request when Firefox crashes; see below.

Testing

  • Unit tests on a private bus: the caller disconnects mid-request, with and without a request handle, and the caller is already gone before the watch is set up. All three report Cancelled. They fail with a timeout when the watch is disabled.
  • End to end with real Firefox 158, the web extension and native helper, xdg-desktop-portal built from credential: Pass request handle to the handler xdg-desktop-portal#1, and the daemon and UI from this branch:
    • Killing xdg-desktop-portal with kill -9 during a create request: the daemon logged "Caller left the bus" 12 ms later, cancelled the request and the UI closed.
    • Killing the native helper: the portal called Close() and the request was cancelled. This is the existing daemon: Allow clients to cancel requests #246 path, and it still works.
    • A new request after a cancel works normally.

Found while testing: a Firefox crash still leaves the request open

When Firefox is killed mid-request, the native helper (webext/app/credential_manager_shim.py) keeps running. It waits on the portal call and doesn't notice that Firefox has gone, so the request and dialog stay open until the helper's own 5-minute timeout. 45 s after the kill the helper was still running. That needs a fix in the helper, for example watching stdin for EOF, and is not part of this PR. I can open an issue for it.

With linux-credentials#246, a client can cancel a request explicitly with Close(), but a
request whose caller leaves the bus unexpectedly, e.g. because it crashed,
stays open until the user dismisses the UI.

Watch the caller's unique name for the duration of the ceremony and cancel
the request once it has no owner. NameHasOwner is checked after subscribing
to NameOwnerChanged, so a caller that left before the watch was set up is
caught too. This works with and without a request handle. If setting up the
watch fails, the request goes on as before.

In the portal setup the caller is xdg-desktop-portal, which already closes
the handler request when the app that made it goes away. This covers the
portal itself going away, and callers that talk to the daemon directly.

Fixes linux-credentials#274

@iinuwa iinuwa 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.

I was literally writing the same thing last night!

},
None => None,
};

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.

merging for now, but this can be simplified: we don't support P2P connections, and we rely on the bus, so there will always be a sender. returning an error on an empty sender would flatten this.

@iinuwa
iinuwa merged commit e584cb2 into linux-credentials:main Nov 20, 2026
1 check passed
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.

Cancel request when client disconnects

2 participants