From a7ba0d2e870b2b7cbc62e38df8f33aa550ab8f23 Mon Sep 17 00:00:00 2001 From: Brian Hursey Date: Tue, 1 Dec 2026 12:13:54 +0000 Subject: [PATCH] Start the Windows bundle when the network is disconnected The launcher asked /api/health through Invoke-WebRequest, which resolves the system proxy or PAC script before it looks at the URL; with no network every probe timed out and the launcher killed a healthy local process after two minutes and reported that Luminary had not started. Both launchers now probe 127.0.0.1 over a raw TCP socket, which uses no proxy, DNS or certificate store, and the app window is started with --no-proxy-server. --- windows/README.md | 7 ++++++- windows/launcher/DESIGN.md | 9 +++++++-- windows/launcher/Luminary.ps1 | 33 ++++++++++++++++++++++++++++++--- windows/launcher/go/main.go | 16 +++++++++++++++- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/windows/README.md b/windows/README.md index 2ffb441..cdcdc4d 100644 --- a/windows/README.md +++ b/windows/README.md @@ -343,6 +343,11 @@ then replaces `node.exe`. It refuses while Luminary is running. Set - No tray icon and no auto-update in this version (both are launcher features, not app changes). - Loopback only by default; set `HOST=0.0.0.0` for LAN proofing galleries. +- Fully offline: the app, the catalog and the start-up wait are local. The + launcher probes `127.0.0.1` over plain TCP, which never consults the system + proxy or DNS, so a disconnected network, VPN or proxy setting cannot stop it + from starting. Only `-Repair` (downloading `node.exe`) and the optional Immich + sync use the network. - The PowerShell launcher cannot clean up after a server crash; a stale `runtime.json` is simply ignored on the next start. - The setup exe cannot be executed on the Linux build host. It is verified by @@ -360,7 +365,7 @@ then replaces `node.exe`. It refuses while Luminary is running. Set | "Luminary needs Windows 10 or 11" (exit 4) | the launcher read `CurrentBuild` below 10240. The app targets Windows 10/11; there is no Windows 7/8 build | | "The Universal C Runtime is missing" | Windows 8.1 without KB2999226 — install or use Windows 10/11 | | "The data drive has only … GB free" | free space before starting; catalogs and previews grow in `%LOCALAPPDATA%` | -| "did not answer on /api/health" | `logs\server.err.log`; run `node app\server\index.mjs` from `app\` to see the failure | +| "did not answer on /api/health" | `logs\server.err.log`; run `node app\server\index.mjs` from `app\` to see the failure. This is not a network error: start-up only talks to `127.0.0.1`, so a disconnected machine starts the same way | | Browser opens an error page | the port was taken between the check and the spawn; start again | | RAW import fails | `app\node_modules\@img\sharp-win32-x64` must contain a `.node` binary; RAW decode itself is wasm | | `node.exe failed its SHA-256 check` | delete `/cache` and rebuild (the download was truncated) | diff --git a/windows/launcher/DESIGN.md b/windows/launcher/DESIGN.md index 704fb08..64ea94c 100644 --- a/windows/launcher/DESIGN.md +++ b/windows/launcher/DESIGN.md @@ -142,8 +142,13 @@ create data dir → create log dir → pick port → spawn node.exe (hidden) second or third attempt). - The PowerShell launcher checks `$process.HasExited` first, so a crash reports the log instead of waiting the full timeout. -- The browser is opened only after health succeeds; opening earlier shows a - connection error on slow machines. +- The probe is a raw HTTP request over TCP to `127.0.0.1`, in both launchers, + and never `Invoke-WebRequest` or a proxy-aware HTTP client. WinINET resolves + the system proxy (a PAC script or WPAD) before it looks at the URL, which can + block for far longer than the request timeout on a machine with no network; + the server was healthy the whole time, but every probe timed out and the + launcher reported that Luminary had not started. Start-up must never depend on + a connection, a proxy setting or DNS. Logs are append-only: `logs\server.out.log` and `logs\server.err.log` from the child, `logs\launcher.log` from the Go launcher. They fall back to diff --git a/windows/launcher/Luminary.ps1 b/windows/launcher/Luminary.ps1 index 180f84b..04454bd 100644 --- a/windows/launcher/Luminary.ps1 +++ b/windows/launcher/Luminary.ps1 @@ -96,11 +96,34 @@ function Read-Runtime { try { return Get-Content -Raw -LiteralPath $runtimeFile | ConvertFrom-Json } catch { return $null } } +# Loopback liveness probe. +# +# Invoke-WebRequest goes through WinINET, which resolves the system proxy (a PAC +# script or WPAD) before it looks at the URL. On a machine with no network that +# lookup can block for far longer than -TimeoutSec, so every probe timed out and +# the launcher killed a healthy local server: the app "would not start" offline. +# A raw request over TCP to 127.0.0.1 uses no proxy, DNS or certificate store, so +# start-up behaves the same with or without a connection. function Test-Health([int]$port) { + $client = $null try { - $response = Invoke-WebRequest -UseBasicParsing -TimeoutSec 2 -Uri ("http://127.0.0.1:{0}/api/health" -f $port) - return ($response.StatusCode -eq 200) - } catch { return $false } + $client = New-Object System.Net.Sockets.TcpClient + $connect = $client.ConnectAsync([System.Net.IPAddress]::Loopback, $port) + if (-not $connect.Wait(2000)) { return $false } + $client.ReceiveTimeout = 3000 + $stream = $client.GetStream() + $request = [System.Text.Encoding]::ASCII.GetBytes(( + "GET /api/health HTTP/1.0`r`nHost: 127.0.0.1:{0}`r`nConnection: close`r`n`r`n" -f $port)) + $stream.Write($request, 0, $request.Length) + $stream.Flush() + $reader = New-Object System.IO.StreamReader($stream, [System.Text.Encoding]::ASCII) + $status = $reader.ReadLine() + return ($status -match '^HTTP/1\.[01] 200\b') + } catch { + return $false + } finally { + if ($client) { $client.Close() } + } } function Test-Process([int]$processId) { @@ -183,12 +206,16 @@ function Open-App([string]$url) { $profile = Join-Path (Get-DataDir) 'window-profile' try { New-Item -ItemType Directory -Force -Path $profile | Out-Null + # --no-proxy-server: the window only ever loads 127.0.0.1. A proxy or PAC + # script set on the machine must not be able to intercept (or stall) it + # when the network is down. Start-Process -FilePath $exe -ArgumentList @( "--app=$url", "--user-data-dir=$profile", '--window-size=1500,950', '--no-first-run', '--no-default-browser-check', + '--no-proxy-server', '--disable-features=Translate' ) | Out-Null } catch { diff --git a/windows/launcher/go/main.go b/windows/launcher/go/main.go index 7c56517..8b22e09 100644 --- a/windows/launcher/go/main.go +++ b/windows/launcher/go/main.go @@ -58,7 +58,17 @@ var ( user32 = syscall.NewLazyDLL("user32.dll") messageBoxW = user32.NewProc("MessageBoxW") - client = &http.Client{Timeout: 2 * time.Second} + // Health is a loopback call: no proxy, no DNS, no internet. The default + // transport honours HTTP_PROXY, so a stale corporate proxy or PAC script + // would make every probe fail and the launcher would kill a server that was + // already answering. + client = &http.Client{ + Timeout: 2 * time.Second, + Transport: &http.Transport{ + Proxy: nil, + DialContext: (&net.Dialer{Timeout: 2 * time.Second}).DialContext, + }, + } downloadClient = &http.Client{Timeout: 10 * time.Minute} nodePinRE = regexp.MustCompile(`^node\s+v?(\d+\.\d+\.\d+)\s+win-x64(?:\s+sha256\s+([0-9a-f]{64}))?(?:\s+size\s+(\d+))?`) ) @@ -621,12 +631,16 @@ func openApp(url string) { openBrowser(url) return } + // --no-proxy-server: the window only ever loads 127.0.0.1, so a proxy or + // PAC script on the machine must not intercept or stall it when the + // network is down. cmd := exec.Command(exe, "--app="+url, "--user-data-dir="+profile, "--window-size=1500,950", "--no-first-run", "--no-default-browser-check", + "--no-proxy-server", "--disable-features=Translate", ) if err := cmd.Start(); err != nil {