tamperward 2.29.18 → 2.29.19

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/cli/index.js +33 -3
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -13024,6 +13024,8 @@ async function startHookService(opts) {
13024
13024
  const cache3 = opts.cache ?? new SnapshotCache();
13025
13025
  let served = 0;
13026
13026
  let inFlight = false;
13027
+ const sockets = /* @__PURE__ */ new Set();
13028
+ let acceptedSocket = null;
13027
13029
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
13028
13030
  const respond = (sock, body) => {
13029
13031
  try {
@@ -13056,6 +13058,7 @@ async function startHookService(opts) {
13056
13058
  if (named !== null && !within(root, named)) return respond(sock, { refused: "payload cwd outside the bound repository" });
13057
13059
  if (inFlight) return respond(sock, { refused: "another request is in flight" });
13058
13060
  inFlight = true;
13061
+ acceptedSocket = sock;
13059
13062
  sock.write(JSON.stringify({ v: HOOK_SERVICE_PROTOCOL, version: TW_VERSION, accepted: true }) + "\n");
13060
13063
  setImmediate(() => {
13061
13064
  try {
@@ -13074,24 +13077,38 @@ async function startHookService(opts) {
13074
13077
  respond(sock, { exitCode: result.exitCode, stdout: result.stdout });
13075
13078
  } finally {
13076
13079
  inFlight = false;
13080
+ acceptedSocket = null;
13077
13081
  }
13078
13082
  });
13079
13083
  };
13080
13084
  const server = createServer((sock) => {
13085
+ sockets.add(sock);
13081
13086
  let buf = "";
13082
13087
  let answered = false;
13083
13088
  sock.setEncoding("utf8");
13089
+ const deadline = setTimeout(() => {
13090
+ if (answered) return;
13091
+ answered = true;
13092
+ respond(sock, { refused: "request deadline exceeded" });
13093
+ }, REQUEST_DEADLINE_MS);
13094
+ deadline.unref?.();
13084
13095
  sock.on("error", () => sock.destroy());
13096
+ sock.on("close", () => {
13097
+ clearTimeout(deadline);
13098
+ sockets.delete(sock);
13099
+ });
13085
13100
  sock.on("data", (chunk) => {
13086
13101
  if (answered) return;
13087
13102
  buf += chunk;
13088
13103
  if (buf.length > MAX_REQUEST_BYTES) {
13089
13104
  answered = true;
13105
+ clearTimeout(deadline);
13090
13106
  return respond(sock, { refused: "request too large" });
13091
13107
  }
13092
13108
  const nl = buf.indexOf("\n");
13093
13109
  if (nl < 0) return;
13094
13110
  answered = true;
13111
+ clearTimeout(deadline);
13095
13112
  handle(sock, buf.slice(0, nl));
13096
13113
  });
13097
13114
  });
@@ -13122,11 +13139,22 @@ async function startHookService(opts) {
13122
13139
  if (closed) return resolve17();
13123
13140
  closed = true;
13124
13141
  setSnapshotCache(null);
13125
- server.close(() => {
13142
+ let settled = false;
13143
+ let drain;
13144
+ const finalize = () => {
13145
+ if (settled) return;
13146
+ settled = true;
13147
+ clearTimeout(drain);
13126
13148
  removeQuietly(paths.socket);
13127
13149
  removeQuietly(paths.state);
13128
13150
  resolve17();
13129
- });
13151
+ };
13152
+ server.close(finalize);
13153
+ for (const sock of sockets) if (sock !== acceptedSocket) sock.destroy();
13154
+ drain = setTimeout(() => {
13155
+ for (const sock of sockets) sock.destroy();
13156
+ }, SHUTDOWN_DRAIN_MS);
13157
+ drain.unref?.();
13130
13158
  })
13131
13159
  };
13132
13160
  }
@@ -13264,7 +13292,7 @@ function runHookService(args) {
13264
13292
  });
13265
13293
  return -1;
13266
13294
  }
13267
- var MAX_REQUEST_BYTES, STOP_WAIT_MS;
13295
+ var MAX_REQUEST_BYTES, STOP_WAIT_MS, REQUEST_DEADLINE_MS, SHUTDOWN_DRAIN_MS;
13268
13296
  var init_hook_service = __esm({
13269
13297
  "src/cli/hook-service.ts"() {
13270
13298
  "use strict";
@@ -13277,6 +13305,8 @@ var init_hook_service = __esm({
13277
13305
  init_hook_client();
13278
13306
  MAX_REQUEST_BYTES = 64 * 1024 * 1024;
13279
13307
  STOP_WAIT_MS = 1e4;
13308
+ REQUEST_DEADLINE_MS = 3e4;
13309
+ SHUTDOWN_DRAIN_MS = 5e3;
13280
13310
  }
13281
13311
  });
13282
13312
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tamperward",
3
- "version": "2.29.18",
3
+ "version": "2.29.19",
4
4
  "description": "The deterministic agent-integrity gate. One ruleset, evaluated on the actual diff/commands as a verdict, enforced everywhere a change can be made.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "hexrift",