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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user