Repository navigation
Prevent clipboard capture hangs - #9488
Conversation
aholbreich
left a comment
There was a problem hiding this comment.
Thanks for this. I reran your fake-wl-paste harness against quattro and this branch (0a9d2c49) and got the same numbers: 3.02 s before, 2.02 s after for the stalled --list-types, and 3.02 s → 2.01 s for the snapshot read. The two timeouts look correct and safe to me. I also checked that a password-manager copy is still skipped when --list-types times out: in watch mode wl-paste sets CLIPBOARD_STATE=sensitive itself from the same x-kde-passwordManagerHint type, so line 15 still exits.
One hang path is still open, and I think it is the one behind #9443. In watch mode, capture.sh's stdin is the pipe from the clipboard owner (wl-paste dup2s it and then blocks in waitpid(), wl-paste.c L198, L218). emit_text and emit_image read that pipe to EOF with no bound. If the owner keeps its end open without closing it (frozen, or the fd leaked to a child process), the callback never exits. It reproduces on this branch for both text and image:
{ printf 'copied'; sleep 12; } | timeout 8 shell/plugins/clipboard/capture.sh text # still killed by the outer 8 s guard
{ printf 'PNG'; sleep 12; } | timeout 8 shell/plugins/clipboard/capture.sh image/png # sameTwo hints that this, not line 13, is what hung in #9443:
wl-paste --list-typesnever opens a pipe to the owner. It prints the offered types and exits (wl-paste.c L280-285), so an owner going away can't stall it.- The
psfilter in #9443 (grep -E "wl-paste|capture\.sh") would have shown a stuckwl-paste --list-typeschild, and none is listed. A stuckperl(emit_text) wouldn't match that filter.
Possible fixes, either one:
- bound the stdin read in
capture.sh:text) timeout 2s cat | emit_textand the same forimage/*, or - bound the whole callback in
Clipboard.qml:"wl-paste", "--type", "text", "--watch", "timeout", "5s", root.captureScript, "text"(same for the image watcher), which also covers any wait added later. A longer limit is kinder to large images.
Small nit: if the snapshot read on line 105 times out partway through, emit_text still writes what it received so far. With a fake that sends half, pauses 3 s, then sends the rest, this branch records "first half ", while quattro records the full text. It only affects the one snapshot at shell start. Skipping the entry when timeout exits with 124 would avoid it.
In watch mode capture.sh reads the copy from the owner's pipe on stdin, to EOF, with no bound. An owner that stalls without closing its end keeps the callback alive, and wl-paste --watch handles no further clipboard events until it exits. That matches omacom#9443, whose stuck capture.sh had no wl-paste child: --list-types never reads from the owner. Every read now goes through one bounded reader into a temporary file, and the copy is recorded only when the read finished, so a snapshot that stalls halfway no longer records its first half. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewed, reproduced on a worker built from the Omarchy ISO, and fixed in one commit pushed to this branch (b147c75). What was still open. @aholbreich's review is right, and I've followed it. What b147c75 changes. Every read in Tested on the worker. Second opinion. Codex at medium effort reviewed the change. It found no defect in the stdin bound or the tests, and its agreement there is not independent: it can read this session's work. It also raised something I had not reasoned about: when For the maintainer. One trade-off to decide: the two-second limit covers the whole read, so a large image that is still streaming after two seconds is now dropped from history instead of recorded. The clipboard itself is untouched. The snapshot image read already had this limit. #11920 (an |
|
| mkdir -p "$IMAGE_DIR" | ||
|
|
||
| types=$(wl-paste --list-types 2>/dev/null || true) | ||
| types=$(timeout 2s wl-paste --list-types 2>/dev/null || true) |
There was a problem hiding this comment.
If a clipboard item carries x-kde-passwordManagerHint, CLIPBOARD_STATE is unset, and --list-types takes more than two seconds, the timeout leaves types empty. The hint check then misses the marker, while the watched-text branch still reads stdin and emits JSON. Password-manager text can be saved to clipboard history.
How this was verified: The timed-out MIME result feeds the hint check, while the watched-text branch emits its stdin payload regardless of that result.
| } | ||
|
|
||
| emit_text() { | ||
| tmp=$(mktemp --tmpdir="$STATE_DIR" clipboard.XXXXXX) || return 0 |
There was a problem hiding this comment.
Interrupted captures leave text behind
Text is now written to a temporary file in the state directory, but cleanup relies on an EXIT trap. If the capture process is forcibly terminated while reading, the file can remain on disk with raw clipboard text. This adds a non-blocking cleanup and privacy concern; handle interruption cleanup or avoid staging text on disk.
|
Reviewed b147c75 against current On a disposable worker built from the Omarchy ISO, an independent producer kept its payload pipe open. Text and image capture hung on Greptile’s password warning does not apply: wl-clipboard exports The temporary-file finding is a real, nonblocking limitation. A force-killed capture can leave an owner-only ( The current- Codex Medium’s second opinion found no merge blockers; its agreement is not guaranteed to be independent. One review round completed within a three-round bound. A legitimate transfer taking over two seconds is omitted from history; the clipboard itself is unchanged. #11920 overlaps this file and must account for this fix if it lands later. Nothing remains for the author; this waits on the maintainer. |
wl-paste --watchwaits for each capture callback before handling another clipboard event. An owner that stalls without closing the payload pipe can therefore leavecapture.shwaiting for EOF indefinitely, silently stopping clipboard history as reported in #9443.Bound MIME queries and every payload read, including watched stdin and startup snapshots, to two seconds. Stage each payload before decoding or hashing it, and emit an entry only when the read completes successfully. Incomplete transfers are dropped and their temporary files are removed on normal exit. This prevents recording a truncated copy and allows the watcher to process subsequent events. A legitimate transfer taking longer than two seconds is omitted from history; the clipboard itself is unchanged.
Fixes #9443