@mostra/runtime 0.6.1 → 0.6.2

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/dist/bin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as uninstallService, i as serviceStatus, n as startInstance, o as checkPlatform, r as installService, s as resolveHomePath, t as runtimeVersion } from "./instance-BfGOToHo.js";
2
+ import { a as uninstallService, i as serviceStatus, n as startInstance, o as checkPlatform, r as installService, s as resolveHomePath, t as runtimeVersion } from "./instance-DpD340-W.js";
3
3
  import { s as realPath } from "./files-FygSJIzK.js";
4
4
  import { mkdirSync } from "node:fs";
5
5
  import { fileURLToPath } from "node:url";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as startInstance, t as runtimeVersion } from "./instance-BfGOToHo.js";
1
+ import { n as startInstance, t as runtimeVersion } from "./instance-DpD340-W.js";
2
2
  import { t as connectToSupervisor } from "./child-Chiavhdx.js";
3
3
  export { connectToSupervisor, runtimeVersion, startInstance };
@@ -9336,6 +9336,14 @@ function mount(app, checks, routes) {
9336
9336
  * host's cookies (D98 item 9).
9337
9337
  */
9338
9338
  const MAX_HEADER_SIZE = 1048576;
9339
+ /**
9340
+ * How long a listener keeps an idle connection open: longer than browsers keep theirs (Chromium
9341
+ * 300 s, Firefox 115 s), so the browser reuses its connections and closes them itself (D157 item
9342
+ * 2). Node's default, 5 s, made the gateway close first, and each connection it closed stayed in
9343
+ * TIME_WAIT on its side, where Chromium's random local ports on Windows collided with it and
9344
+ * failed the connect at once with `ERR_NO_BUFFER_SPACE` (#66).
9345
+ */
9346
+ const KEEP_ALIVE_MS = 305e3;
9339
9347
  /** Writes a refusal straight to a socket, for upgrades and envelope failures before Hono. */
9340
9348
  function writeRaw(socket, refused, extra = {}) {
9341
9349
  const body = extra.html ?? JSON.stringify(refused.diagnostic);
@@ -9392,6 +9400,48 @@ function headersTooLarge(socket) {
9392
9400
  headers: ["clear-site-data: \"cookies\"", "content-security-policy: default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'; base-uri 'none'"]
9393
9401
  });
9394
9402
  }
9403
+ /**
9404
+ * Records every connection and request of a listener in the supervisor's log: its arrival and its
9405
+ * end, whether it was answered, with the time between them and the client's port, so a request a
9406
+ * browser saw go unanswered shows whether it ever reached the gateway (#66). Only a request's
9407
+ * method and path are kept, never its query (a frame ticket travels there) or its headers; a test
9408
+ * switch (`MOSTRA_TEST_REQUEST_LOG`), since a long-lived daemon would log every asset it serves.
9409
+ */
9410
+ function traceRequests(server, log, origin) {
9411
+ server.on("connection", (socket) => {
9412
+ const opened = Date.now();
9413
+ const client = socket.remotePort;
9414
+ log.info("gateway.connection", {
9415
+ origin: origin(),
9416
+ client
9417
+ });
9418
+ socket.once("close", (hadError) => log.info("gateway.connection_closed", {
9419
+ origin: origin(),
9420
+ client,
9421
+ ms: Date.now() - opened,
9422
+ read: socket.bytesRead,
9423
+ written: socket.bytesWritten,
9424
+ ...hadError ? { hadError } : {}
9425
+ }));
9426
+ });
9427
+ server.prependListener("request", (incoming, outgoing) => {
9428
+ const started = Date.now();
9429
+ const fields = {
9430
+ origin: origin(),
9431
+ client: incoming.socket.remotePort,
9432
+ method: incoming.method,
9433
+ path: (incoming.url ?? "").replace(/[?#].*$/s, "")
9434
+ };
9435
+ log.info("gateway.request", fields);
9436
+ outgoing.once("close", () => log.info("gateway.request_closed", {
9437
+ ...fields,
9438
+ status: outgoing.statusCode,
9439
+ headersSent: outgoing.headersSent,
9440
+ finished: outgoing.writableFinished,
9441
+ ms: Date.now() - started
9442
+ }));
9443
+ });
9444
+ }
9395
9445
  /** Creates a listener whose routes `configure` mounts; the server isn't bound yet. */
9396
9446
  function createListener(options) {
9397
9447
  const app = new Hono();
@@ -9444,6 +9494,7 @@ function createListener(options) {
9444
9494
  }
9445
9495
  listener(incoming, outgoing);
9446
9496
  });
9497
+ if (options.traceRequests) traceRequests(server, options.log, () => options.policy().origin);
9447
9498
  server.on("clientError", (error, socket) => {
9448
9499
  if (refusedSockets.has(socket)) return;
9449
9500
  if (!socket.writable) {
@@ -9480,6 +9531,7 @@ function createListener(options) {
9480
9531
  });
9481
9532
  server.headersTimeout = 3e4;
9482
9533
  server.requestTimeout = 12e4;
9534
+ server.keepAliveTimeout = KEEP_ALIVE_MS;
9483
9535
  return {
9484
9536
  server,
9485
9537
  app,
@@ -10463,7 +10515,8 @@ function createGateway(options) {
10463
10515
  log,
10464
10516
  frameAncestors: () => shellOrigin(),
10465
10517
  configure: (app) => mount(app, artifactChecks(artifactId, () => port), artifactRoutes(artifactId, () => port)),
10466
- ...options.dev ? { upgrade: devSocket(artifactId, () => port) } : {}
10518
+ ...options.dev ? { upgrade: devSocket(artifactId, () => port) } : {},
10519
+ ...options.traceRequests ? { traceRequests: true } : {}
10467
10520
  });
10468
10521
  port = await addressing.listen(listener.server, {
10469
10522
  purpose: "artifact",
@@ -10515,7 +10568,8 @@ function createGateway(options) {
10515
10568
  policy: () => shellChecks.policy(),
10516
10569
  log,
10517
10570
  frameAncestors: () => "'none'",
10518
- configure: (app) => mount(app, shellChecks, shellRoutes)
10571
+ configure: (app) => mount(app, shellChecks, shellRoutes),
10572
+ ...options.traceRequests ? { traceRequests: true } : {}
10519
10573
  });
10520
10574
  shellPort = await addressing.listen(shellListener.server, {
10521
10575
  purpose: "shell",
@@ -16342,9 +16396,12 @@ async function assemble(home, options) {
16342
16396
  actions.recover();
16343
16397
  const shellDir = locateShell(environment);
16344
16398
  if (shellDir === void 0) log.warn("gateway.shell_missing", { code: "MOSTRA_ENV_SHELL_MISSING" });
16399
+ const traceRequests = Boolean(environment["MOSTRA_TEST_REQUEST_LOG"]);
16400
+ if (traceRequests) log.warn("instance.test_request_log", {});
16345
16401
  const gateway = createGateway({
16346
16402
  ledger: home.ledger,
16347
16403
  log,
16404
+ ...traceRequests ? { traceRequests } : {},
16348
16405
  addressing,
16349
16406
  capabilities,
16350
16407
  artifacts: {
@@ -16690,4 +16747,4 @@ function sourceDirectory(path) {
16690
16747
  //#endregion
16691
16748
  export { uninstallService as a, serviceStatus as i, startInstance as n, checkPlatform as o, installService as r, resolveHomePath as s, runtimeVersion as t };
16692
16749
 
16693
- //# sourceMappingURL=instance-BfGOToHo.js.map
16750
+ //# sourceMappingURL=instance-DpD340-W.js.map