@holin-work/holin-cli 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/holin-cli.js +41 -13
- package/package.json +1 -1
package/bin/holin-cli.js
CHANGED
|
@@ -557,10 +557,46 @@ function cmdProxyStart() {
|
|
|
557
557
|
process.on("SIGTERM", cleanupAndExit);
|
|
558
558
|
}
|
|
559
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Wait until the proxy port is actually accepting TCP connections.
|
|
562
|
+
* Polls every 200ms up to `timeoutMs`. Resolves when the port is reachable,
|
|
563
|
+
* rejects on timeout.
|
|
564
|
+
*/
|
|
565
|
+
function waitForPort(port, host, timeoutMs) {
|
|
566
|
+
return new Promise((resolve, reject) => {
|
|
567
|
+
const deadline = Date.now() + timeoutMs;
|
|
568
|
+
function attempt() {
|
|
569
|
+
const req = http.get({ hostname: host, port, path: "/health", timeout: 500 }, (res) => {
|
|
570
|
+
res.resume(); // drain response body
|
|
571
|
+
req.destroy();
|
|
572
|
+
resolve();
|
|
573
|
+
});
|
|
574
|
+
req.on("error", () => {
|
|
575
|
+
req.destroy();
|
|
576
|
+
if (Date.now() >= deadline) {
|
|
577
|
+
reject(new Error(`Proxy port ${port} not reachable within ${timeoutMs}ms. Check log: ${LOG_FILE}`));
|
|
578
|
+
} else {
|
|
579
|
+
setTimeout(attempt, 200);
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
req.on("timeout", () => {
|
|
583
|
+
req.destroy();
|
|
584
|
+
if (Date.now() >= deadline) {
|
|
585
|
+
reject(new Error(`Proxy port ${port} not reachable within ${timeoutMs}ms. Check log: ${LOG_FILE}`));
|
|
586
|
+
} else {
|
|
587
|
+
setTimeout(attempt, 200);
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
attempt();
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
|
|
560
595
|
function startProxyDaemon() {
|
|
561
596
|
return new Promise((resolve, reject) => {
|
|
562
597
|
if (isProxyRunning()) {
|
|
563
|
-
|
|
598
|
+
// Proxy process exists per pid file — also verify port is actually listening
|
|
599
|
+
waitForPort(PROXY_PORT, PROXY_HOST, 3000).then(resolve).catch(resolve); // best-effort
|
|
564
600
|
return;
|
|
565
601
|
}
|
|
566
602
|
|
|
@@ -574,18 +610,10 @@ function startProxyDaemon() {
|
|
|
574
610
|
|
|
575
611
|
child.unref();
|
|
576
612
|
|
|
577
|
-
//
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
if (isProxyRunning()) {
|
|
582
|
-
clearInterval(poll);
|
|
583
|
-
resolve();
|
|
584
|
-
} else if (attempts >= 15) {
|
|
585
|
-
clearInterval(poll);
|
|
586
|
-
reject(new Error(`Proxy did not start within 3s. Check log: ${LOG_FILE}`));
|
|
587
|
-
}
|
|
588
|
-
}, 200);
|
|
613
|
+
// Wait until the proxy port is actually accepting connections (up to 10s).
|
|
614
|
+
// This replaces the old pid-file poll which only confirmed the process existed,
|
|
615
|
+
// not that it was ready to serve — causing ECONNREFUSED races on slow machines.
|
|
616
|
+
waitForPort(PROXY_PORT, PROXY_HOST, 10000).then(resolve).catch(reject);
|
|
589
617
|
});
|
|
590
618
|
}
|
|
591
619
|
|