@rallycry/conveyor-k3 0.1.5 → 0.1.6

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.
Files changed (2) hide show
  1. package/dist/vm-qemu.js +27 -19
  2. package/package.json +1 -1
package/dist/vm-qemu.js CHANGED
@@ -472,7 +472,7 @@ import { join } from "path";
472
472
  import { Socket } from "net";
473
473
  var MAX_RELAYS = 16;
474
474
  var MAX_RELAY_BYTES = 1024 * 1024 * 1024;
475
- var RELAY_LIFETIME_MS = 6e4;
475
+ var RELAY_CONNECT_MS = 6e4;
476
476
  var RELAY_IDLE_MS = 3e4;
477
477
  var GUARD_FRESH_MS = 6e3;
478
478
  var RELAY_PREFIX = "--conveyor-vm-relay";
@@ -665,10 +665,10 @@ function currentGuardStillValid(root, runId) {
665
665
  return false;
666
666
  }
667
667
  }
668
- function runRelay(root, invocation) {
669
- return Promise.resolve().then(() => runRelayNow(root, invocation));
668
+ function runRelay(root, invocation, io) {
669
+ return Promise.resolve().then(() => runRelayNow(root, invocation, io));
670
670
  }
671
- function runRelayNow(root, invocation) {
671
+ function runRelayNow(root, invocation, io) {
672
672
  const guard = readLiveGuard(root);
673
673
  assertApprovedDestination(root, invocation);
674
674
  const record = registerRelay(root, guard.runId);
@@ -677,15 +677,19 @@ function runRelayNow(root, invocation) {
677
677
  let sent = 0;
678
678
  let received = 0;
679
679
  let guardTimer;
680
- let lifetimeTimer;
681
- const socket = new Socket();
680
+ let connectTimer;
681
+ const { socket, input, output } = io ?? {
682
+ socket: new Socket(),
683
+ input: process.stdin,
684
+ output: process.stdout
685
+ };
682
686
  const finish = (error) => {
683
687
  if (finished) return;
684
688
  finished = true;
685
689
  if (guardTimer) clearInterval(guardTimer);
686
- if (lifetimeTimer) clearTimeout(lifetimeTimer);
690
+ if (connectTimer) clearTimeout(connectTimer);
687
691
  socket.destroy();
688
- process.stdin.destroy();
692
+ input.destroy();
689
693
  try {
690
694
  unregisterRelay(root, record);
691
695
  } catch {
@@ -695,30 +699,34 @@ function runRelayNow(root, invocation) {
695
699
  };
696
700
  const exceedsLimit = (total) => total > MAX_RELAY_BYTES;
697
701
  socket.setTimeout(RELAY_IDLE_MS, () => finish(new Error("VM relay idle timeout")));
702
+ socket.once("connect", () => {
703
+ if (connectTimer) clearTimeout(connectTimer);
704
+ connectTimer = void 0;
705
+ });
698
706
  socket.on("error", () => finish(new Error("VM relay connection failed")));
699
707
  socket.on("close", () => finish());
700
708
  socket.on("data", (chunk) => {
701
709
  received += chunk.length;
702
710
  if (exceedsLimit(received)) return finish(new Error("VM relay receive limit exceeded"));
703
- if (!process.stdout.write(chunk)) socket.pause();
711
+ if (!output.write(chunk)) socket.pause();
704
712
  });
705
- process.stdout.on("drain", () => socket.resume());
706
- process.stdout.on("error", () => finish(new Error("VM relay output failed")));
707
- process.stdin.on("data", (chunk) => {
713
+ output.on("drain", () => socket.resume());
714
+ output.on("error", () => finish(new Error("VM relay output failed")));
715
+ input.on("data", (chunk) => {
708
716
  sent += chunk.length;
709
717
  if (exceedsLimit(sent)) return finish(new Error("VM relay send limit exceeded"));
710
- if (!socket.write(chunk)) process.stdin.pause();
718
+ if (!socket.write(chunk)) input.pause();
711
719
  });
712
- socket.on("drain", () => process.stdin.resume());
713
- process.stdin.on("end", () => socket.end());
714
- process.stdin.on("error", () => finish(new Error("VM relay input failed")));
720
+ socket.on("drain", () => input.resume());
721
+ input.on("end", () => socket.end());
722
+ input.on("error", () => finish(new Error("VM relay input failed")));
715
723
  guardTimer = setInterval(() => {
716
724
  if (!currentGuardStillValid(root, record.runId))
717
725
  finish(new Error("VM relay guard is no longer healthy"));
718
726
  }, 2e3);
719
- lifetimeTimer = setTimeout(
720
- () => finish(new Error("VM relay lifetime exceeded")),
721
- RELAY_LIFETIME_MS
727
+ connectTimer = setTimeout(
728
+ () => finish(new Error("VM relay connection timed out")),
729
+ RELAY_CONNECT_MS
722
730
  );
723
731
  socket.connect(invocation.port, invocation.address);
724
732
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rallycry/conveyor-k3",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Managed personal compute for Conveyor. Installs and maintains a k3s cluster that runs your own card builds, kept converged on Conveyor's desired state.",
5
5
  "keywords": [
6
6
  "cloudflared",