Skip to content

fix(linux): close Wayland sharing sessions after capture - #3986

Merged
richiemcilroy merged 2 commits into
CapSoftware:mainfrom
AksharP5:close-wayland-session
Nov 16, 2026
Merged

richiemcilroy merged 2 commits into
CapSoftware:mainfrom
AksharP5:close-wayland-session

Conversation

@AksharP5

@AksharP5 AksharP5 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Cap does not explicitly close its ScreenCast portal session when Wayland capture ends. On backends that retain it after the PipeWire consumer disconnects, repeated attempts can accumulate sessions until Cap exits. The shared D-Bus connection remains alive for the process lifetime.

Register session cleanup immediately after acquisition, using the existing pipeline cleanup scope. Drop of the capture owner releases the worker to close the portal session; the lifecycle waits for its acknowledgement. Real close failures keep cleanup unconfirmed, while an already-removed session counts as closed. Startup cancellation and fd-open errors use the same ownership path.

The regression runs the actual acquisition/owner and cleanup scope against a private D-Bus service. A Unix socket pair represents the remote fd; no compositor or PipeWire daemon is used.

Same two capture-owner acquisitions and drops Before After
Remote descriptors Both closed Both closed
Portal Session.Close calls 0 2
Portal sessions left alive 2 0

Validation: the actual native regression passes all seven private-bus child cases, and the full cap-recording library suite passes 948 tests with 14 ignored. The unchanged production-source negative control leaves two sessions open. Three additional isolated probes pass for an unresponsive Close timeout, cleanup outside a scope, and a scope waiting while the capture owner remains alive. Full locked crate checking, formatting and workflow parsing pass. Strict Clippy on host Rust 1.99.1 reports the same 21 pre-existing errors on baseline and patch. Linux CI already runs the recording library suite; setup now explicitly installs dbus-daemon for this test.

No real compositor recording, installed Omarchy session or sharing-indicator appearance was exercised. Retained session resources/indicators are supported by protocol and GNOME source tracing, not a native visual reproduction. This does not claim that recording continues after Stop.

Closes #3985

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issues were found.

Summary

This PR closes Wayland sharing sessions when their capture owner is dropped.

  • Wayland capture sessions close when their capture owner is dropped.

No actionable new issues were found. No previous review threads were supplied. The previous-review range was not used because the merge bases differ. Tests were not run during this review.

Reviews (2) · Last reviewed commit: "Merge origin/main into close-wayland-ses..." · Reviewed by Greptile

@vercel

vercel Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@AksharP5 is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

@richiemcilroy

Copy link
Copy Markdown
Member

Merged current main into this branch and verified it on Ubuntu 24.04 (x86_64).

Reproduced on main (218b056). I ran this PR's wayland_portal_tests.rs against main's unchanged linux.rs. portal_sessions_end_with_capture fails with "dropping captures must close the portal session" (2 sessions still alive, expected 0). ashpd 0.11's Session has close() but no Drop, and its zbus connection lives for the whole process, so on main a session only ends when Cap exits.

On this branch (5354374)

  • portal_sessions_end_with_capture passes (all child cases, 0.3 s).
  • The full cap-recording lib suite passes: 970 passed, 15 ignored.
  • rustfmt is clean, and clippy reports nothing in the changed code (linux.rs shows the same findings as main, outside this diff).

Lifecycle check. The close task registers a scope completion, and PipelineBuildScope::commit() clears completions, so a running recording never waits on it. Failure paths drop the portal session before the caller joins the scope. Close is capped at 3 s, so an unresponsive portal adds at most 3 s to a cancelled start.

Not covered. I couldn't run a real compositor cast. Headless sway 1.9 with xdg-desktop-portal-wlr 0.7.1 creates the session, but Start fails with "unable to receive a valid format from wlr_screencopy" (pixman headless, nested X11, and GLES on vgem all failed), even though grim captures that output fine.

@richiemcilroy

Copy link
Copy Markdown
Member

hey @greptileai, please re-review the PR

@richiemcilroy
richiemcilroy merged commit 7d3b027 into CapSoftware:main Nov 16, 2026
55 of 57 checks 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.

Wayland capture does not close its ScreenCast portal session

2 participants