Skip to content

Fix Wayland FD leak and clipboard sync feedback loop#51

Open
halfcrazy wants to merge 1 commit into
dnut:masterfrom
halfcrazy:fix/wayland-fd-leak-and-sync-loop
Open

Fix Wayland FD leak and clipboard sync feedback loop#51
halfcrazy wants to merge 1 commit into
dnut:masterfrom
halfcrazy:fix/wayland-fd-leak-and-sync-loop

Conversation

@halfcrazy

Copy link
Copy Markdown

Summary

  • Add WlrBackend with a persistent Wayland data-control connection, mirroring the existing X11Backend pattern, so polling no longer opens a new wl-clipboard-rs session on every get()/set() and exhausts file descriptors (EMFILE after ~5 minutes under GNOME Wayland).
  • Upgrade wl-clipboard-rs to 0.9.3 and wayland-client to 0.31.14 (adds ext-data-control support on GNOME).
  • Rewrite keep_synced to track per-clipboard last-known content and add a short post-sync settle period, preventing the X11/Wayland write-lag feedback loop that spammed clipboard updated from display :1 logs.

Fixes #50

Root cause

WlrClipboard called wl_clipboard_rs::paste::get_contents() / copy::Options::copy() on every poll (~5 Hz per clipboard). Each call runs initialize() and opens a new Wayland socket, leaking FDs until ulimit -n is hit.

Separately, after syncing a change, comparing all clipboards against clipboards[0] caused repeated false positives when Wayland and X11 reads diverged briefly after a write.

Test plan

  • Run under GNOME Wayland with WlrClipboard { wayland-1 } + X11Clipboard { :1 }
  • Confirm FD count stays stable (~28) during polling instead of growing ~3–4/sec
  • Copy text on Wayland side; verify it appears on X11 side
  • Confirm only one log line per user copy (no :1 spam)
  • Process survives beyond 10 minutes without EMFILE panic

Made with Cursor

Reuse a persistent Wayland data-control connection in WlrBackend instead
of opening a new wl-clipboard-rs session on every get/set, which caused
EMFILE crashes under polling. Upgrade wl-clipboard-rs and wayland-client,
and rewrite keep_synced to track per-clipboard state with a post-sync
settle period so X11/Wayland write lag no longer spams sync logs.

Fixes dnut#50

Co-authored-by: Cursor <cursoragent@cursor.com>
@halfcrazy
halfcrazy force-pushed the fix/wayland-fd-leak-and-sync-loop branch from 0d60c93 to d8670c4 Compare July 8, 2026 05:17
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.

Crashes with EMFILE (too many open files) due to Wayland connection fd leak in WlrClipboard

1 participant