{"record":{"id":"ac00fe30d2a6567f","repo":"herdrdev/herdr","slug":"windows-notification-setup-timed-out","errorCode":null,"errorMessage":"Windows notification setup timed out","messagePattern":"Windows notification setup timed out","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"warning","filePath":"src/platform/windows.rs","lineNumber":2001,"sourceCode":"    let mut bytes = vec![0_u8; size];\n    unsafe {\n        copy_nonoverlapping(data.cast::<u8>(), bytes.as_mut_ptr(), size);\n        GlobalUnlock(handle);\n    }\n    Some(bytes)\n}\n\npub fn show_desktop_notification(title: &str, body: Option<&str>) -> std::io::Result<bool> {\n    let title = title.to_owned();\n    let body = body.unwrap_or(&title).to_owned();\n    let (ready_tx, ready_rx) = std::sync::mpsc::sync_channel(1);\n    std::thread::Builder::new()\n        .name(\"herdr-windows-notification\".into())\n        .spawn(move || show_desktop_notification_on_thread(&title, &body, ready_tx))?;\n    ready_rx\n        .recv_timeout(Duration::from_secs(2))\n        .map_err(|err| match err {\n            std::sync::mpsc::RecvTimeoutError::Timeout => std::io::Error::new(\n                std::io::ErrorKind::TimedOut,\n                \"Windows notification setup timed out\",\n            ),\n            std::sync::mpsc::RecvTimeoutError::Disconnected => std::io::Error::other(\n                \"Windows notification thread exited before reporting readiness\",\n            ),\n        })?\n}\n\nfn show_desktop_notification_on_thread(\n    title: &str,\n    body: &str,\n    ready_tx: std::sync::mpsc::SyncSender<std::io::Result<bool>>,\n) {\n    let class_name = wide_null(\"STATIC\");\n    let window_name = wide_null(\"Herdr notifications\");\n    let hwnd = unsafe {\n        CreateWindowExW(","sourceCodeStart":1983,"sourceCodeEnd":2019,"githubUrl":"https://github.com/herdrdev/herdr/blob/f457cff4f2648eee85d176f8a41861241d4e8428/src/platform/windows.rs#L1983-L2019","documentation":"Showing a Windows desktop notification happens on a dedicated thread that signals readiness over a channel. If the thread does not report readiness within 2 seconds, this TimedOut error is returned so callers do not block indefinitely on a stuck WinRT/notification setup.","triggerScenarios":"Invoking show_desktop_notification on Windows when the spawned notification thread takes longer than the 2-second recv_timeout to initialize (e.g. COM/WinRT initialization stall, system under load, notification service unresponsive).","commonSituations":"Heavily loaded machines, notification service (WpnService) issues, first COM apartment initialization in a constrained session (SSH/service context without an interactive desktop), or a hung Windows notification API during startup.","solutions":["Retry the notification; transient setup stalls under load usually succeed on a second attempt","Check that Windows notifications are enabled for the app and WpnUserService/WpnService is running","If running over SSH or as a service, ensure an interactive desktop session exists — WinRT toast needs one","Report/inspect Herdr logs for the companion 'thread exited before reporting readiness' error to distinguish a crash from a stall"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match show_desktop_notification(title, body) {\n    Ok(()) => {}\n    Err(e) if e.kind() == std::io::ErrorKind::TimedOut => {\n        // one bounded retry; notifications are best-effort\n        let _ = show_desktop_notification(title, body);\n    }\n    Err(_) => {} // never fail the user flow on a notification\n}","preventionTips":["Treat notifications as best-effort: log failures, never propagate them to the UI flow","Bound retries to one or two attempts to avoid notification storms on a stuck system","Check WpnService health and interactive-session availability when the error repeats","Distinguish Timeout from the Disconnected 'thread exited' error — the latter indicates a crash, not a stall"],"tags":["windows","notification","timeout","thread","winrt"],"backgroundTag":"operation-timed-out","analyzedSha":"f457cff4f2648eee85d176f8a41861241d4e8428","analyzedAt":"2026-08-28T15:41:09.197Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}