siyuan-note/siyuan · warning

open clipboard timeout

Error message

open clipboard timeout

What it means

On Windows, the clipboard is a shared global resource that must be opened before writing. waitOpenClipboard retries w32.OpenClipboard repeatedly until a deadline (about a second) to tolerate other applications holding the clipboard open; if it cannot acquire the clipboard in time it returns this error.

Solutions

  1. Retry the copy operation after a short pause — contention is usually transient
  2. Close or configure clipboard manager/monitor apps that hold the clipboard open continuously
  3. If under RDP, disable clipboard redirection or retry the action outside the contended session

Example fix

// before
err := util.WriteFilePaths(paths) // may hit clipboard contention
// after
var err error
for i := 0; i < 3; i++ {
    if err = util.WriteFilePaths(paths); err == nil || !strings.Contains(err.Error(), "open clipboard timeout") {
        break
    }
    time.Sleep(200 * time.Millisecond)
}
Defensive patterns

Strategy: retry

Validate before calling

// nothing to check beforehand; contention is external and transient
null

Try / catch

if err := util.WriteFilePaths(paths); err != nil {
    if strings.Contains(err.Error(), "open clipboard timeout") {
        time.Sleep(250 * time.Millisecond)
        err = util.WriteFilePaths(paths) // one retry
    }
}

Prevention

When it happens

Trigger: util.WriteFilePaths on Windows when another process keeps the clipboard open for the whole retry window — clipboard managers, remote-desktop sessions, or an app stuck holding an open handle.

Common situations: Running under RDP/Citrix where clipboard synchronization constantly opens the clipboard; clipboard-monitor utilities polling the clipboard; heavy parallel automation (e.g. RPA scripts) hammering OpenClipboard.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/441794f7afa389c1. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/clipboard_windows.go:161

			binary.LittleEndian.PutUint16(buf[offset:offset+2], c)
			offset += 2
		}
	}
	return buf, nil
}

// waitOpenClipboard 在限定时间内重试打开剪贴板。
// 同一时刻仅一进程可持有剪贴板(OpenClipboard 成功)。
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-openclipboard
func waitOpenClipboard() error {
	deadline := time.Now().Add(time.Second)
	for time.Now().Before(deadline) {
		if w32.OpenClipboard(0) {
			return nil
		}
		time.Sleep(time.Millisecond)
	}
	return errors.New("open clipboard timeout")
}

View on GitHub (pinned to 9f775e8a12)