Repository navigation
fix(desktop): generic venv lock handling before update handoff on Windows #75477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
156a104
f128e8d
8874baa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2652,6 +2652,55 @@ function venvHermesShimPath(updateRoot) { | |
| : path.join(updateRoot, 'venv', 'bin', 'hermes') | ||
| } | ||
|
|
||
| // Every entry-point exe under venv\Scripts (generic — not a hardcoded list). | ||
| function venvScriptsExePaths(updateRoot) { | ||
| const scriptsDir = path.join(updateRoot, 'venv', 'Scripts') | ||
| try { | ||
| return fs | ||
| .readdirSync(scriptsDir) | ||
| .filter((f) => f.toLowerCase().endsWith('.exe')) | ||
| .map((f) => path.join(scriptsDir, f)) | ||
| } catch { | ||
| return [] | ||
| } | ||
| } | ||
|
|
||
| // Generic lock probe across EVERY entry-point exe under venv\Scripts, not a | ||
| // hardcoded shim list: any mapped exe (hindsight daemon's pythonw trampoline, | ||
| // a stray CLI, a future helper) blocks the update the same way. | ||
| function isVenvLocked(updateRoot) { | ||
| if (!IS_WINDOWS) { | ||
| return false | ||
| } | ||
| for (const exe of venvScriptsExePaths(updateRoot)) { | ||
| if (isShimLocked(exe)) { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // Kill every process whose exe lives under venv\Scripts (hindsight daemon, | ||
| // leftover CLIs, anything else) so the updater never races a mapped shim. | ||
| function killVenvShimHolders(updateRoot) { | ||
| if (!IS_WINDOWS) { | ||
| return | ||
| } | ||
| const scriptsDir = path.join(updateRoot, 'venv', 'Scripts').replace(/'/g, "''") | ||
| try { | ||
| const ps = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This force-kills every venv-resident process and its tree, including user-managed terminals, gateways, or services. Current handoff only kills Desktop-owned backend/pool PIDs and reports external holders; please retain that ownership boundary or track a specific Desktop-owned daemon. |
||
| `$p = Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -like '${scriptsDir}\\*' }; ` + | ||
| `foreach ($x in $p) { taskkill /PID $($x.ProcessId) /T /F 2>$null | Out-Null }` | ||
| execFileSync( | ||
| 'powershell', | ||
| ['-NoProfile', '-Command', ps], | ||
| hiddenWindowsChildOptions({ stdio: 'ignore' }) | ||
| ) | ||
| } catch { | ||
| // best-effort: the lock probe below is the real gate | ||
| } | ||
| } | ||
|
|
||
| // Best-effort lock probe mirroring the Rust updater's is_locked(): a running | ||
| // .exe on Windows refuses an O_RDWR open with a sharing violation. On POSIX | ||
| // this practically always succeeds (no mandatory locking), so it returns false | ||
|
|
@@ -2771,12 +2820,15 @@ async function releaseBackendLock(updateRoot, tag) { | |
| forceKillProcessTree(pid) | ||
| } | ||
|
|
||
| const shim = venvHermesShimPath(updateRoot) | ||
| // Kill every venv\Scripts holder (hindsight daemon, stray CLIs, anything | ||
| // else) so the updater never races a mapped pythonw/python/hermes shim. | ||
| killVenvShimHolders(updateRoot) | ||
|
|
||
| const deadlineMs = Date.now() + 15000 | ||
|
|
||
| while (Date.now() < deadlineMs) { | ||
| if (!isShimLocked(shim)) { | ||
| rememberLog(`[${tag}] venv shim unlocked; safe to proceed`) | ||
| if (!isVenvLocked(updateRoot)) { | ||
| rememberLog(`[${tag}] venv shims unlocked; safe to proceed`) | ||
|
|
||
| return { unlocked: true } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not scope this with
-like: it treats legal[/]path characters as wildcard syntax, and this literal emits two backslashes before*. Use an ordinal, case-insensitiveStartsWithcheck against the normalized Scripts prefix, as required bytests/test_install_unmerged_index.py:171-180.