{"record":{"id":"26a5a08e84b644b6","repo":"tonhowtf/omniget","slug":"is-in-use-by-another-process-wait-for-active-downloads-to","errorCode":null,"errorMessage":"{} is in use by another process ({}). Wait for active downloads to finish or cancel them, then try again.","messagePattern":"(.+?) is in use by another process \\((.+?)\\)\\. Wait for active downloads to finish or cancel them, then try again\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/dependencies.rs","lineNumber":344,"sourceCode":"    target: &std::path::Path,\n) -> anyhow::Result<()> {\n    if !target.exists() {\n        std::fs::rename(temp, target)\n            .map_err(|e| anyhow!(\"Failed to move {} into place: {}\", target.display(), e))?;\n        return Ok(());\n    }\n\n    if cfg!(windows) {\n        let file_name = target\n            .file_name()\n            .and_then(|n| n.to_str())\n            .unwrap_or(\"binary\")\n            .to_string();\n        let old = target.with_file_name(format!(\"{}.old\", file_name));\n        let _ = std::fs::remove_file(&old);\n        if let Err(e) = std::fs::rename(target, &old) {\n            let _ = std::fs::remove_file(temp);\n            return Err(anyhow!(\n                \"{} is in use by another process ({}). Wait for active downloads to finish or cancel them, then try again.\",\n                file_name,\n                e\n            ));\n        }\n        if let Err(e) = std::fs::rename(temp, target) {\n            let _ = std::fs::rename(&old, target);\n            let _ = std::fs::remove_file(temp);\n            return Err(anyhow!(\"Failed to replace {}: {}\", file_name, e));\n        }\n        let _ = std::fs::remove_file(&old);\n        Ok(())\n    } else {\n        std::fs::rename(temp, target)\n            .map_err(|e| anyhow!(\"Failed to replace {}: {}\", target.display(), e))?;\n        Ok(())\n    }\n}","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/dependencies.rs#L326-L362","documentation":"Thrown by replace_managed_binary on Windows when renaming the existing target binary to '<name>.old' fails, which almost always means the file is locked by a running process. The temp download is cleaned up and a user-actionable message is returned telling them to stop active downloads/processes.","triggerScenarios":"download_ffmpeg -> replace_managed_binary on Windows with cfg!(windows): the old ffmpeg.exe (or other managed binary) is currently executing or memory-mapped by this app, yt-dlp, antivirus, or another process, so fs::rename(target, .old) fails with a sharing/lock error.","commonSituations":"Updating ffmpeg while a download that shells out to it is running; antivirus holding a handle on the exe; the app itself spawned ffmpeg and hasn't reaped it; another instance of the app running.","solutions":["Cancel/wait for all active downloads and any spawned ffmpeg/yt-dlp processes, then retry the update.","Kill lingering ffmpeg.exe processes (Task Manager or taskkill /IM ffmpeg.exe).","Temporarily exclude the app's binary directory from antivirus scanning if AV keeps the handle.","Restart the app so it no longer holds inherited handles, then update."],"exampleFix":"// before (caller)\nupdate_ffmpeg().await?; // fails while a download is running\n// after\nwait_for_idle_downloads().await;\nupdate_ffmpeg().await?;","handlingStrategy":"validation","validationCode":"// Windows: fail fast (or wait) when the binary is still running\n#[cfg(windows)]\nfn binary_idle(target: &std::path::Path) -> bool {\n    match std::fs::rename(target, target.with_file_name(\".probe_lock\")) {\n        Ok(()) => { let _ = std::fs::rename(target.with_file_name(\".probe_lock\"), target); true }\n        Err(_) => false,\n    }\n}","typeGuard":null,"tryCatchPattern":"match replace_managed_binary(&temp, &target).await {\n    Ok(()) => {},\n    Err(e) if format!(\"{e}\").contains(\"in use by another process\") => {\n        wait_for_active_downloads().await;\n        replace_managed_binary(&temp, &target).await?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Gate binary updates on 'no active downloads/spawned ffmpeg' state.","Track and reap child ffmpeg/yt-dlp processes before updating.","Document the '.old' rollback mechanism so users know a failed update is safe to retry."],"tags":["windows","filesystem","file-lock","update"],"backgroundTag":"file-in-use-locked","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}