Skip to content

Freeze buf fix - #207

Merged
wiiznokes merged 10 commits into
cosmic-utils:masterfrom
dafaqboomduck:freeze_buf_fix
Oct 25, 2026
Merged

wiiznokes merged 10 commits into
cosmic-utils:masterfrom
dafaqboomduck:freeze_buf_fix

Conversation

@dafaqboomduck

@dafaqboomduck dafaqboomduck commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

Clipboard Manager Stability & Freeze Fixes

Fixes #186 — the clipboard manager freezing other applications (Chrome, Sublime Text, Zed, Firefox, Electron apps) under Wayland with XWayland.

Root cause analysis and fix strategy developed with assistance from Claude (Anthropic).


Freeze Fixes

X11 atom filtering (clipboard_watcher.rs) — XWayland apps advertise X11 negotiation atoms (SAVE_TARGETS, TARGETS, MULTIPLE, TIMESTAMP, COMPOUND_TEXT) that poison Chrome/Electron's clipboard thread when requested. Added a blocklist to skip these before calling offer.receive().

Wayland queue flush (clipboard_watcher.rs) — offer.receive() only buffers requests client-side. Without queue.flush() afterward, the compositor never sees them, and pipes block forever. Added flush after the receive loop.

Async concurrent pipe reads with timeout (clipboard.rs, Cargo.toml) — Replaced synchronous sequential pipe.read_to_end() (which blocked the entire async runtime) with concurrent async reads via tokio::net::unix::pipe::Receiver + futures::future::join_all, each wrapped in a 500ms tokio::time::timeout. Total wall time is now capped at 500ms regardless of MIME type count.

Error Handling Fixes

  • Replaced panic!()/unwrap() throughout main.rs, clipboard_watcher.rs, and clipboard.rs with graceful error handling and warning logs
  • Fixed GlobalError::InvalidId panic ("How's this possible?") with proper error variant
  • Fixed memory leak — offers HashMap now cleans up replaced offers
  • Added error classification system (ErrorRecoverable vs ErrorFatal) so transient failures don't permanently kill the clipboard

Testing

Tested on Pop!_OS 24.04 LTS with COSMIC. Copy/paste from XWayland apps (VS Code, Claude Desktop/Electron) works without freezes. Rapid stress testing is stable. Debug logs confirm atoms are filtered and no timeouts on well-behaved sources.

RUST_LOG=warn,cosmic_ext_applet_clipboard_manager=debug cargo run

@dafaqboomduck
dafaqboomduck marked this pull request as draft April 10, 2026 09:21
@dafaqboomduck
dafaqboomduck marked this pull request as ready for review April 10, 2026 10:58
@wiiznokes

Copy link
Copy Markdown
Collaborator

i don't think it's only xwayland app that cause this, because firefox also caused problem iirc

@PACHAKUTlQ

Copy link
Copy Markdown

i don't think it's only xwayland app that cause this, because firefox also caused problem iirc

That might be a different issue.

I experience the whole COSMIC DE freezing sometimes and I never use xwayland. The screen does not respond anymore I have to long-press the power button to force shutdown. I experienced similar issue in pop-os/cosmic-screenshot#216.

So this is not exactly "freezing other apps". Just to say there are more bugs out there that causes some kind of freezing.

dafaqboomduck and others added 10 commits October 25, 2026 10:08
…cher and clipboard modules

- **Graceful startup failure handling**: Replace `panic!` with `std::process::exit(1)` for critical startup errors in config and applet initialization
- **Enhanced error recovery**: Introduce `RegistryInvalidId` and `OfferNotFound` error variants in `clipboard_watcher.rs`; replace `unwrap()` with `if let` patterns for seat lookups to prevent panics
- **Fixed offer lifecycle**: `set_offer` and `set_primary_offer` now return old offers to avoid memory leaks; event handlers now clean up stale entries before updating
- **Channel safety and error classification**: Replace `unwrap()` in `clipboard.rs` with graceful exits on channel closure; introduce `ClipboardMessage::ErrorRecoverable` and `ErrorFatal` variants, along with `is_recoverable()` method for structured error handling
- **Removed pending hangs**: Eliminated `std::future::pending()` after errors to ensure consistent program termination
- **App state updates**: `app.rs` now distinguishes between recoverable and fatal errors, logging and continuing for recoverable cases while updating state for fatal ones

These changes ensure robust error handling, prevent process crashes, and maintain clean resource management across critical operations.
- Apply cargo fmt formatting to clipboard.rs and clipboard_watcher.rs
- Add STABILITY_FIXES.md documenting all Phase 2 fixes and future work

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dafaqboomduck

dafaqboomduck commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed merge conflicts; @wiiznokes merge?

test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 4.32s

@wiiznokes
wiiznokes enabled auto-merge (squash) October 25, 2026 10:58
@wiiznokes
wiiznokes merged commit 27a246f into cosmic-utils:master Oct 25, 2026
5 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.

Freezing other apps in Cosmic Pop Os

3 participants