{"record":{"id":"c06141d833a7531d","repo":"astrid-runtime/astrid","slug":"winfsp-stop-deadline-overflow","errorCode":null,"errorMessage":"WinFsp stop deadline overflow","messagePattern":"WinFsp stop deadline overflow","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-storage-provider-winfsp/src/win.rs","lineNumber":672,"sourceCode":"            .context(\"send WinFsp stop\")?;\n        stream.flush().await.context(\"flush WinFsp stop\")?;\n        let mut acknowledgement = [0_u8; 1];\n        stream\n            .read_exact(&mut acknowledgement)\n            .await\n            .context(\"read WinFsp stop acknowledgement\")?;\n        if acknowledgement[0] != b'S' {\n            bail!(\"WinFsp daemon returned an invalid stop acknowledgement\");\n        }\n        Result::<()>::Ok(())\n    };\n    tokio::time::timeout(DAEMON_STOP_TIMEOUT, stop)\n        .await\n        .map_err(|_| anyhow::anyhow!(\"WinFsp stop timed out\"))??;\n\n    let deadline = tokio::time::Instant::now()\n        .checked_add(DAEMON_STOP_TIMEOUT)\n        .ok_or_else(|| anyhow::anyhow!(\"WinFsp stop deadline overflow\"))?;\n    while endpoint_is_present(control_path) {\n        if tokio::time::Instant::now() >= deadline {\n            bail!(\"WinFsp control endpoint remained live after stop\");\n        }\n        tokio::time::sleep(Duration::from_millis(25)).await;\n    }\n    Ok(())\n}\n\nfn initialize_winfsp() -> Result<()> {\n    load_adjacent_winfsp().context(\"load co-installed WinFsp runtime\")?;\n    winfsp_wrs::init().context(\"initialize installed WinFsp runtime\")\n}\n\nfn load_adjacent_winfsp() -> Result<()> {\n    let Some(directory) = std::env::current_exe()\n        .ok()\n        .and_then(|path| path.parent().map(Path::to_path_buf))","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-provider-winfsp/src/win.rs#L654-L690","documentation":"Raised in `stop_daemon` (crates/astrid-storage-provider-winfsp/src/win.rs:672) when `Instant::checked_add(DAEMON_STOP_TIMEOUT, now)` returns `None`, i.e. computing the post-stop polling deadline overflows the `tokio::time::Instant` range. This is effectively unreachable in practice (it requires a near-max timestamp) and is a defensive guard so deadline arithmetic never silently wraps into a poll loop that would spin until the 'endpoint remained live' bail.","triggerScenarios":"Specifically: `tokio::time::Instant::now().checked_add(DAEMON_STOP_TIMEOUT)` yields `None`. This requires the current monotonic instant plus `DAEMON_STOP_TIMEOUT` to exceed the internal representable maximum — an extreme/edge runtime-clock situation, not a user-fixable configuration issue.","commonSituations":"Essentially never seen by end users; it could only appear with a pathological monotonic clock value (e.g. u64::MAX-adjacent tick on an embedded/VM host with a broken clock, or after enormous fake-time offsets in tests using paused/auto-advance tokio time).","solutions":["Treat it as an environmental clock anomaly: reboot the host or fix the monotonic clock source.","In tests, avoid advancing tokio time to near-`Instant` saturation before calling `stop_daemon`.","If it recurs on real hardware, update the tokio runtime; file a bug including the runtime/clock details.","As a workaround, compute the deadline with `saturating_add` semantics by clamping the timeout."],"exampleFix":"// before\nlet deadline = tokio::time::Instant::now()\n    .checked_add(DAEMON_STOP_TIMEOUT)\n    .ok_or_else(|| anyhow::anyhow!(\"WinFsp stop deadline overflow\"))?;\n// after (saturating alternative)\nlet deadline = tokio::time::Instant::now()\n    .checked_add(DAEMON_STOP_TIMEOUT)\n    .unwrap_or_else(tokio::time::Instant::now);\nlet deadline = deadline + Duration::from_millis(1);","handlingStrategy":"fallback","validationCode":"// Only relevant in tests using paused tokio time:\nassert!(tokio::time::Instant::now().checked_add(DAEMON_STOP_TIMEOUT).is_some());","typeGuard":null,"tryCatchPattern":"let deadline = tokio::time::Instant::now()\n    .checked_add(DAEMON_STOP_TIMEOUT)\n    .ok_or_else(|| anyhow::anyhow!(\"WinFsp stop deadline overflow\"))?;\n// callers: treat as environment failure and abort teardown with diagnostics\nmatch stop_daemon(&control_path).await {\n    Err(e) if e.to_string().contains(\"deadline overflow\") => {\n        error!(\"clock anomaly detected; reboot/fix monotonic clock\");\n    },\n    other => { other?; }\n}","preventionTips":["Avoid advancing tokio test time to near-Instant saturation before invoking stop paths.","Treat this as a host clock anomaly; verify the monotonic clock on affected machines.","Prefer saturating deadline arithmetic in new code paths where a bounded delay suffices."],"tags":["winfsp","timeout","clock-overflow","shutdown","defensive"],"backgroundTag":"value-out-of-range","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}