vibelet 1.0.6 → 1.0.8
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/vibelet.mjs +24 -14
- package/dist/index.cjs +51 -48
- package/package.json +1 -19
package/bin/vibelet.mjs
CHANGED
|
@@ -522,7 +522,9 @@ async function probeHealth(timeoutMs = 0) {
|
|
|
522
522
|
const deadline = Date.now() + timeoutMs;
|
|
523
523
|
do {
|
|
524
524
|
try {
|
|
525
|
-
const response = await fetch(`http://127.0.0.1:${port}/health
|
|
525
|
+
const response = await fetch(`http://127.0.0.1:${port}/health`, {
|
|
526
|
+
signal: AbortSignal.timeout(1500),
|
|
527
|
+
});
|
|
526
528
|
if (response.ok) {
|
|
527
529
|
return await response.json();
|
|
528
530
|
}
|
|
@@ -535,6 +537,16 @@ async function probeHealth(timeoutMs = 0) {
|
|
|
535
537
|
return null;
|
|
536
538
|
}
|
|
537
539
|
|
|
540
|
+
async function waitForDaemonExit(timeoutMs) {
|
|
541
|
+
const deadline = Date.now() + timeoutMs;
|
|
542
|
+
while (Date.now() < deadline) {
|
|
543
|
+
const health = await probeHealth(0);
|
|
544
|
+
if (!health) return true;
|
|
545
|
+
await new Promise((resolvePromise) => setTimeout(resolvePromise, 200));
|
|
546
|
+
}
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
|
|
538
550
|
async function waitForHealth(timeoutMs = 10_000) {
|
|
539
551
|
const health = await probeHealth(timeoutMs);
|
|
540
552
|
if (health) {
|
|
@@ -558,18 +570,15 @@ async function postJson(pathname, body = undefined) {
|
|
|
558
570
|
|
|
559
571
|
async function requestShutdown() {
|
|
560
572
|
try {
|
|
561
|
-
await fetch(`http://127.0.0.1:${port}/shutdown`, {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
const health = await probeHealth(0);
|
|
566
|
-
if (!health) return true;
|
|
567
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
568
|
-
}
|
|
569
|
-
return false;
|
|
573
|
+
await fetch(`http://127.0.0.1:${port}/shutdown`, {
|
|
574
|
+
method: 'POST',
|
|
575
|
+
signal: AbortSignal.timeout(2000),
|
|
576
|
+
});
|
|
570
577
|
} catch {
|
|
571
|
-
|
|
578
|
+
// Request timed out or connection refused — daemon may be deadlocked or
|
|
579
|
+
// already gone. Either way, fall through to polling for actual exit.
|
|
572
580
|
}
|
|
581
|
+
return waitForDaemonExit(5_000);
|
|
573
582
|
}
|
|
574
583
|
|
|
575
584
|
function isDaemonStartCommand(command) {
|
|
@@ -577,10 +586,11 @@ function isDaemonStartCommand(command) {
|
|
|
577
586
|
}
|
|
578
587
|
|
|
579
588
|
async function stopRunningDaemon(backend) {
|
|
580
|
-
await requestShutdown();
|
|
589
|
+
const gracefullyStopped = await requestShutdown();
|
|
581
590
|
backend.stop();
|
|
582
|
-
|
|
583
|
-
|
|
591
|
+
if (gracefullyStopped) return;
|
|
592
|
+
const died = await waitForDaemonExit(5_000);
|
|
593
|
+
if (!died) {
|
|
584
594
|
fail('Daemon did not stop in time.');
|
|
585
595
|
}
|
|
586
596
|
}
|