{"record":{"id":"441794f7afa389c1","repo":"siyuan-note/siyuan","slug":"open-clipboard-timeout","errorCode":null,"errorMessage":"open clipboard timeout","messagePattern":"open clipboard timeout","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/util/clipboard_windows.go","lineNumber":161,"sourceCode":"\t\t\tbinary.LittleEndian.PutUint16(buf[offset:offset+2], c)\n\t\t\toffset += 2\n\t\t}\n\t}\n\treturn buf, nil\n}\n\n// waitOpenClipboard 在限定时间内重试打开剪贴板。\n// 同一时刻仅一进程可持有剪贴板（OpenClipboard 成功）。\n// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-openclipboard\nfunc waitOpenClipboard() error {\n\tdeadline := time.Now().Add(time.Second)\n\tfor time.Now().Before(deadline) {\n\t\tif w32.OpenClipboard(0) {\n\t\t\treturn nil\n\t\t}\n\t\ttime.Sleep(time.Millisecond)\n\t}\n\treturn errors.New(\"open clipboard timeout\")\n}\n","sourceCodeStart":143,"sourceCodeEnd":163,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/clipboard_windows.go#L143-L163","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the copy operation after a short pause — contention is usually transient","Close or configure clipboard manager/monitor apps that hold the clipboard open continuously","If under RDP, disable clipboard redirection or retry the action outside the contended session"],"exampleFix":"// before\nerr := util.WriteFilePaths(paths) // may hit clipboard contention\n// after\nvar err error\nfor i := 0; i < 3; i++ {\n    if err = util.WriteFilePaths(paths); err == nil || !strings.Contains(err.Error(), \"open clipboard timeout\") {\n        break\n    }\n    time.Sleep(200 * time.Millisecond)\n}","handlingStrategy":"retry","validationCode":"// nothing to check beforehand; contention is external and transient\nnull","typeGuard":null,"tryCatchPattern":"if err := util.WriteFilePaths(paths); err != nil {\n    if strings.Contains(err.Error(), \"open clipboard timeout\") {\n        time.Sleep(250 * time.Millisecond)\n        err = util.WriteFilePaths(paths) // one retry\n    }\n}","preventionTips":["Pause/limit clipboard-manager utilities that poll OpenClipboard on the machine","Batch file copies to reduce clipboard open/close churn","In RDP sessions, disable clipboard redirection if writes keep timing out"],"tags":["clipboard","windows","timeout","contention"],"backgroundTag":"request-timeout","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}