ai-or-die 0.1.91 → 0.1.92
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/package.json +1 -1
- package/src/mesh-manager.js +28 -0
package/package.json
CHANGED
package/src/mesh-manager.js
CHANGED
|
@@ -19,6 +19,10 @@ const MIN_RESTART_DELAY_MS = 1000;
|
|
|
19
19
|
const MAX_RESTART_DELAY_MS = 30000;
|
|
20
20
|
const MAX_RETRIES = 10;
|
|
21
21
|
const MESH_PEERS_JSON_MAX = 256 * 1024;
|
|
22
|
+
// The sidecar announces MESH-EGRESS once at spawn, but a consumer treats
|
|
23
|
+
// egress.json stale past a short TTL (~120s). Re-stamp its updatedAt on this
|
|
24
|
+
// cadence while the sidecar lives so a healthy egress never looks stale.
|
|
25
|
+
const MESH_EGRESS_REFRESH_MS = 30000;
|
|
22
26
|
|
|
23
27
|
class MeshManager {
|
|
24
28
|
constructor(options = {}) {
|
|
@@ -61,6 +65,8 @@ class MeshManager {
|
|
|
61
65
|
this._stdoutBuffer = '';
|
|
62
66
|
this.peers = null;
|
|
63
67
|
this._untaggedWarned = false;
|
|
68
|
+
this._egress = null;
|
|
69
|
+
this._egressRefreshTimer = null;
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
/** Never throws — degrades to localhost/devtunnel on any failure. */
|
|
@@ -279,7 +285,9 @@ class MeshManager {
|
|
|
279
285
|
// consumer's DNS/hosts config could rebind off-host.
|
|
280
286
|
if (host !== '127.0.0.1' && host !== '::1') return;
|
|
281
287
|
if (!token || /\s/.test(token)) return;
|
|
288
|
+
this._egress = { url, token };
|
|
282
289
|
this._writeEgressFile(url, token);
|
|
290
|
+
this._startEgressRefresh();
|
|
283
291
|
}
|
|
284
292
|
|
|
285
293
|
_writeEgressFile(url, token) {
|
|
@@ -304,7 +312,27 @@ class MeshManager {
|
|
|
304
312
|
}
|
|
305
313
|
}
|
|
306
314
|
|
|
315
|
+
// Keep egress.json's updatedAt fresh while the sidecar is alive. Without this a
|
|
316
|
+
// consumer's freshness TTL rejects the (write-once) egress after ~2 min of
|
|
317
|
+
// uptime and the mesh silently fails closed. Stops itself once the sidecar exits.
|
|
318
|
+
_startEgressRefresh() {
|
|
319
|
+
if (this._egressRefreshTimer) return;
|
|
320
|
+
this._egressRefreshTimer = setInterval(() => this._refreshEgressTick(), MESH_EGRESS_REFRESH_MS);
|
|
321
|
+
if (this._egressRefreshTimer.unref) this._egressRefreshTimer.unref();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
_refreshEgressTick() {
|
|
325
|
+
if (this.proc && this._egress) this._writeEgressFile(this._egress.url, this._egress.token);
|
|
326
|
+
else this._stopEgressRefresh();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
_stopEgressRefresh() {
|
|
330
|
+
if (this._egressRefreshTimer) { clearInterval(this._egressRefreshTimer); this._egressRefreshTimer = null; }
|
|
331
|
+
}
|
|
332
|
+
|
|
307
333
|
_deleteEgressFile() {
|
|
334
|
+
this._egress = null;
|
|
335
|
+
this._stopEgressRefresh();
|
|
308
336
|
try { fs.rmSync(this.egressFilePath(), { force: true }); } catch (_) {}
|
|
309
337
|
}
|
|
310
338
|
|