@resolveio/server-lib 22.2.57 → 22.3.0
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/http/auth.js +9 -6
- package/http/auth.js.map +1 -1
- package/managers/mongo.manager.d.ts +12 -10
- package/managers/mongo.manager.js +2 -2
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.js +59 -53
- package/managers/subscription.manager.js.map +1 -1
- package/methods/monitor.js +2 -2
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js.map +1 -1
- package/package.json +67 -67
- package/server-app.d.ts +53 -0
- package/server-app.js +629 -44
- package/server-app.js.map +1 -1
package/server-app.js
CHANGED
|
@@ -85,6 +85,7 @@ var os = require("os");
|
|
|
85
85
|
var path = require("path");
|
|
86
86
|
var perf_hooks_1 = require("perf_hooks");
|
|
87
87
|
var inspector = require("inspector");
|
|
88
|
+
var child_process_1 = require("child_process");
|
|
88
89
|
var url_1 = require("url");
|
|
89
90
|
var WebSocket = require("ws");
|
|
90
91
|
var log_collection_1 = require("./collections/log.collection");
|
|
@@ -166,6 +167,22 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
166
167
|
this._timerDebugLogLimit = 100;
|
|
167
168
|
this._timerDebugLogCount = 0;
|
|
168
169
|
this._aiWorkerDebug = false;
|
|
170
|
+
this._standaloneNodeReaperEnabled = false;
|
|
171
|
+
this._standaloneNodeReaperIntervalMs = 60000;
|
|
172
|
+
this._standaloneNodeReaperMinAgeSeconds = 300;
|
|
173
|
+
this._standaloneNodeReaperMaxKillsPerSignature = 1;
|
|
174
|
+
this._standaloneNodeReaperKillWindowMs = 60 * 60 * 1000;
|
|
175
|
+
this._standaloneNodeReaperIncludeSystemdServices = false;
|
|
176
|
+
this._standaloneNodeReaperHighCpuPct = 85;
|
|
177
|
+
this._standaloneNodeReaperHighRssMb = 4096;
|
|
178
|
+
this._standaloneNodeReaperHighMinAgeSeconds = 60;
|
|
179
|
+
this._standaloneNodeReaperHighConsecutiveScans = 2;
|
|
180
|
+
this._standaloneNodeReaperDryRun = false;
|
|
181
|
+
this._standaloneNodeReaperTimer = null;
|
|
182
|
+
this._standaloneNodeReaperRunning = false;
|
|
183
|
+
this._standaloneNodeReaperKillCounts = new Map();
|
|
184
|
+
this._standaloneNodeReaperSuppressedSignatures = new Set();
|
|
185
|
+
this._standaloneNodeReaperResourceHits = new Map();
|
|
169
186
|
this._lastErrorMsg = null;
|
|
170
187
|
this._debugMsgRecv = 0;
|
|
171
188
|
this._debugMsgQueue = 0;
|
|
@@ -221,6 +238,17 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
221
238
|
this._timerDebugSampleRate = this.resolveTimerDebugSampleRate();
|
|
222
239
|
this._timerDebugLogLimit = this.resolveTimerDebugLogLimit();
|
|
223
240
|
this._aiWorkerDebug = this.parseDebugFlag(process.env.AI_ASSISTANT_WORKER_DEBUG);
|
|
241
|
+
this._standaloneNodeReaperEnabled = this.resolveStandaloneNodeReaperEnabled();
|
|
242
|
+
this._standaloneNodeReaperIntervalMs = this.resolveStandaloneNodeReaperIntervalMs();
|
|
243
|
+
this._standaloneNodeReaperMinAgeSeconds = this.resolveStandaloneNodeReaperMinAgeSeconds();
|
|
244
|
+
this._standaloneNodeReaperMaxKillsPerSignature = this.resolveStandaloneNodeReaperMaxKillsPerSignature();
|
|
245
|
+
this._standaloneNodeReaperKillWindowMs = this.resolveStandaloneNodeReaperKillWindowMs();
|
|
246
|
+
this._standaloneNodeReaperIncludeSystemdServices = this.resolveStandaloneNodeReaperIncludeSystemdServices();
|
|
247
|
+
this._standaloneNodeReaperHighCpuPct = this.resolveStandaloneNodeReaperHighCpuPct();
|
|
248
|
+
this._standaloneNodeReaperHighRssMb = this.resolveStandaloneNodeReaperHighRssMb();
|
|
249
|
+
this._standaloneNodeReaperHighMinAgeSeconds = this.resolveStandaloneNodeReaperHighMinAgeSeconds();
|
|
250
|
+
this._standaloneNodeReaperHighConsecutiveScans = this.resolveStandaloneNodeReaperHighConsecutiveScans();
|
|
251
|
+
this._standaloneNodeReaperDryRun = this.resolveStandaloneNodeReaperDryRun();
|
|
224
252
|
this._dynamicAppGatewayEnabled = this.resolveDynamicAppGatewayEnabled();
|
|
225
253
|
this._socketTier = this.resolveSocketTier();
|
|
226
254
|
this._maxClientSockets = this.resolveMaxClientSockets(this._socketTier);
|
|
@@ -246,6 +274,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
246
274
|
// Check for workers and decide what to start
|
|
247
275
|
this._isWorkersEnabled = process.env.IS_WORKERS_ENABLED === 'true';
|
|
248
276
|
this._isWorkerInstance = process.env.IS_WORKER_INSTANCE === 'true';
|
|
277
|
+
this.startStandaloneNodeReaper();
|
|
249
278
|
setInterval(function () {
|
|
250
279
|
if (_this._methodManager && _this._methodManager.getEnableDebug()) {
|
|
251
280
|
console.log(new Date(), 'Server App', 'Msg Recv Hits', _this._debugMsgRecv);
|
|
@@ -510,6 +539,476 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
510
539
|
resolveio_server_app_1.ResolveIOServer['AiAssistantCodexManager'] = null;
|
|
511
540
|
}
|
|
512
541
|
};
|
|
542
|
+
ResolveIOMainServer.prototype.startStandaloneNodeReaper = function () {
|
|
543
|
+
var _this = this;
|
|
544
|
+
var _a, _b, _c;
|
|
545
|
+
if (!this._standaloneNodeReaperEnabled || this._standaloneNodeReaperTimer) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (process.platform !== 'linux' || !this.isPm2ManagedRuntime() || !this.isPrimaryPm2Instance()) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
var initialDelayMs = Math.min(30000, this._standaloneNodeReaperIntervalMs);
|
|
552
|
+
var firstRunTimer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
553
|
+
var error_4;
|
|
554
|
+
return __generator(this, function (_a) {
|
|
555
|
+
switch (_a.label) {
|
|
556
|
+
case 0:
|
|
557
|
+
_a.trys.push([0, 2, , 3]);
|
|
558
|
+
return [4 /*yield*/, this.reapStandaloneNodeProcesses()];
|
|
559
|
+
case 1:
|
|
560
|
+
_a.sent();
|
|
561
|
+
return [3 /*break*/, 3];
|
|
562
|
+
case 2:
|
|
563
|
+
error_4 = _a.sent();
|
|
564
|
+
console.error(new Date(), '[Standalone Node Reaper] failed', error_4);
|
|
565
|
+
return [3 /*break*/, 3];
|
|
566
|
+
case 3: return [2 /*return*/];
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}); }, initialDelayMs);
|
|
570
|
+
(_a = firstRunTimer.unref) === null || _a === void 0 ? void 0 : _a.call(firstRunTimer);
|
|
571
|
+
this._standaloneNodeReaperTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
572
|
+
var error_5;
|
|
573
|
+
return __generator(this, function (_a) {
|
|
574
|
+
switch (_a.label) {
|
|
575
|
+
case 0:
|
|
576
|
+
_a.trys.push([0, 2, , 3]);
|
|
577
|
+
return [4 /*yield*/, this.reapStandaloneNodeProcesses()];
|
|
578
|
+
case 1:
|
|
579
|
+
_a.sent();
|
|
580
|
+
return [3 /*break*/, 3];
|
|
581
|
+
case 2:
|
|
582
|
+
error_5 = _a.sent();
|
|
583
|
+
console.error(new Date(), '[Standalone Node Reaper] failed', error_5);
|
|
584
|
+
return [3 /*break*/, 3];
|
|
585
|
+
case 3: return [2 /*return*/];
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}); }, this._standaloneNodeReaperIntervalMs);
|
|
589
|
+
(_c = (_b = this._standaloneNodeReaperTimer).unref) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
590
|
+
console.log(new Date(), '[Standalone Node Reaper] enabled', {
|
|
591
|
+
intervalMs: this._standaloneNodeReaperIntervalMs,
|
|
592
|
+
minAgeSeconds: this._standaloneNodeReaperMinAgeSeconds,
|
|
593
|
+
maxKillsPerSignature: this._standaloneNodeReaperMaxKillsPerSignature,
|
|
594
|
+
killWindowMs: this._standaloneNodeReaperKillWindowMs,
|
|
595
|
+
highCpuPct: this._standaloneNodeReaperHighCpuPct,
|
|
596
|
+
highRssMb: this._standaloneNodeReaperHighRssMb,
|
|
597
|
+
highMinAgeSeconds: this._standaloneNodeReaperHighMinAgeSeconds,
|
|
598
|
+
highConsecutiveScans: this._standaloneNodeReaperHighConsecutiveScans,
|
|
599
|
+
dryRun: this._standaloneNodeReaperDryRun
|
|
600
|
+
});
|
|
601
|
+
};
|
|
602
|
+
ResolveIOMainServer.prototype.reapStandaloneNodeProcesses = function () {
|
|
603
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
604
|
+
var processes, protectedPids, _loop_1, this_1, processes_1, processes_1_1, proc;
|
|
605
|
+
var e_1, _a;
|
|
606
|
+
var _b;
|
|
607
|
+
return __generator(this, function (_c) {
|
|
608
|
+
switch (_c.label) {
|
|
609
|
+
case 0:
|
|
610
|
+
if (this._standaloneNodeReaperRunning) {
|
|
611
|
+
return [2 /*return*/];
|
|
612
|
+
}
|
|
613
|
+
this._standaloneNodeReaperRunning = true;
|
|
614
|
+
_c.label = 1;
|
|
615
|
+
case 1:
|
|
616
|
+
_c.trys.push([1, , 3, 4]);
|
|
617
|
+
return [4 /*yield*/, this.listSystemProcesses()];
|
|
618
|
+
case 2:
|
|
619
|
+
processes = _c.sent();
|
|
620
|
+
protectedPids = this.resolvePm2ProtectedPids(processes);
|
|
621
|
+
_loop_1 = function (proc) {
|
|
622
|
+
if (!this_1.shouldReapStandaloneNodeProcess(proc, protectedPids)) {
|
|
623
|
+
return "continue";
|
|
624
|
+
}
|
|
625
|
+
var signature = this_1.resolveStandaloneNodeProcessSignature(proc);
|
|
626
|
+
if (!this_1.canReapStandaloneNodeSignature(signature)) {
|
|
627
|
+
this_1.logStandaloneNodeReaperSuppressed(proc, signature);
|
|
628
|
+
return "continue";
|
|
629
|
+
}
|
|
630
|
+
var reason = this_1.resolveStandaloneNodeReaperReason(proc);
|
|
631
|
+
if (this_1._standaloneNodeReaperDryRun) {
|
|
632
|
+
this_1.recordStandaloneNodeReaperKill(signature);
|
|
633
|
+
console.warn(new Date(), '[Standalone Node Reaper] dry-run would terminate stale node process', {
|
|
634
|
+
pid: proc.pid,
|
|
635
|
+
ppid: proc.ppid,
|
|
636
|
+
ageSeconds: proc.ageSeconds,
|
|
637
|
+
cpuPct: proc.cpuPct,
|
|
638
|
+
rssMb: (0, common_1.round)(proc.rssKb / 1024),
|
|
639
|
+
reason: reason,
|
|
640
|
+
command: proc.args
|
|
641
|
+
});
|
|
642
|
+
return "continue";
|
|
643
|
+
}
|
|
644
|
+
try {
|
|
645
|
+
process.kill(proc.pid, 'SIGTERM');
|
|
646
|
+
this_1.recordStandaloneNodeReaperKill(signature);
|
|
647
|
+
console.warn(new Date(), '[Standalone Node Reaper] terminated stale node process', {
|
|
648
|
+
pid: proc.pid,
|
|
649
|
+
ppid: proc.ppid,
|
|
650
|
+
ageSeconds: proc.ageSeconds,
|
|
651
|
+
cpuPct: proc.cpuPct,
|
|
652
|
+
rssMb: (0, common_1.round)(proc.rssKb / 1024),
|
|
653
|
+
reason: reason,
|
|
654
|
+
command: proc.args
|
|
655
|
+
});
|
|
656
|
+
var killTimer = setTimeout(function () {
|
|
657
|
+
try {
|
|
658
|
+
process.kill(proc.pid, 0);
|
|
659
|
+
process.kill(proc.pid, 'SIGKILL');
|
|
660
|
+
console.warn(new Date(), '[Standalone Node Reaper] force killed stale node process', {
|
|
661
|
+
pid: proc.pid,
|
|
662
|
+
reason: reason,
|
|
663
|
+
command: proc.args
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
catch (_a) { }
|
|
667
|
+
}, 10000);
|
|
668
|
+
(_b = killTimer.unref) === null || _b === void 0 ? void 0 : _b.call(killTimer);
|
|
669
|
+
}
|
|
670
|
+
catch (error) {
|
|
671
|
+
if ((error === null || error === void 0 ? void 0 : error['code']) !== 'ESRCH') {
|
|
672
|
+
console.error(new Date(), '[Standalone Node Reaper] kill failed', {
|
|
673
|
+
pid: proc.pid,
|
|
674
|
+
command: proc.args,
|
|
675
|
+
error: (error === null || error === void 0 ? void 0 : error['message']) || error
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
this_1 = this;
|
|
681
|
+
try {
|
|
682
|
+
for (processes_1 = __values(processes), processes_1_1 = processes_1.next(); !processes_1_1.done; processes_1_1 = processes_1.next()) {
|
|
683
|
+
proc = processes_1_1.value;
|
|
684
|
+
_loop_1(proc);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
688
|
+
finally {
|
|
689
|
+
try {
|
|
690
|
+
if (processes_1_1 && !processes_1_1.done && (_a = processes_1.return)) _a.call(processes_1);
|
|
691
|
+
}
|
|
692
|
+
finally { if (e_1) throw e_1.error; }
|
|
693
|
+
}
|
|
694
|
+
return [3 /*break*/, 4];
|
|
695
|
+
case 3:
|
|
696
|
+
this._standaloneNodeReaperRunning = false;
|
|
697
|
+
return [7 /*endfinally*/];
|
|
698
|
+
case 4: return [2 /*return*/];
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
};
|
|
703
|
+
ResolveIOMainServer.prototype.listSystemProcesses = function () {
|
|
704
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
705
|
+
var output;
|
|
706
|
+
var _this = this;
|
|
707
|
+
return __generator(this, function (_a) {
|
|
708
|
+
switch (_a.label) {
|
|
709
|
+
case 0: return [4 /*yield*/, this.execFileText('ps', ['-eo', 'pid=,ppid=,etimes=,pcpu=,rss=,comm=,args='], 5000)];
|
|
710
|
+
case 1:
|
|
711
|
+
output = _a.sent();
|
|
712
|
+
return [2 /*return*/, output
|
|
713
|
+
.split('\n')
|
|
714
|
+
.map(function (line) { return line.trim(); })
|
|
715
|
+
.filter(Boolean)
|
|
716
|
+
.map(function (line) { return _this.parseProcessSnapshot(line); })
|
|
717
|
+
.filter(function (proc) { return proc !== null; })];
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
};
|
|
722
|
+
ResolveIOMainServer.prototype.parseProcessSnapshot = function (line) {
|
|
723
|
+
var match = line.match(/^(\d+)\s+(\d+)\s+(\d+)\s+([\d.]+)\s+(\d+)\s+(\S+)\s+(.*)$/);
|
|
724
|
+
if (!match) {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
return {
|
|
728
|
+
pid: parseInt(match[1], 10),
|
|
729
|
+
ppid: parseInt(match[2], 10),
|
|
730
|
+
ageSeconds: parseInt(match[3], 10),
|
|
731
|
+
cpuPct: parseFloat(match[4]),
|
|
732
|
+
rssKb: parseInt(match[5], 10),
|
|
733
|
+
command: match[6],
|
|
734
|
+
args: match[7] || ''
|
|
735
|
+
};
|
|
736
|
+
};
|
|
737
|
+
ResolveIOMainServer.prototype.execFileText = function (command, args, timeoutMs) {
|
|
738
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
739
|
+
return new Promise(function (resolve, reject) {
|
|
740
|
+
(0, child_process_1.execFile)(command, args, { timeout: timeoutMs, maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
|
741
|
+
if (error) {
|
|
742
|
+
reject(error);
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
resolve(stdout || '');
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
ResolveIOMainServer.prototype.resolvePm2ProtectedPids = function (processes) {
|
|
750
|
+
var e_2, _a, e_3, _b;
|
|
751
|
+
var byPid = new Map();
|
|
752
|
+
var children = new Map();
|
|
753
|
+
try {
|
|
754
|
+
for (var processes_2 = __values(processes), processes_2_1 = processes_2.next(); !processes_2_1.done; processes_2_1 = processes_2.next()) {
|
|
755
|
+
var proc = processes_2_1.value;
|
|
756
|
+
byPid.set(proc.pid, proc);
|
|
757
|
+
if (!children.has(proc.ppid)) {
|
|
758
|
+
children.set(proc.ppid, []);
|
|
759
|
+
}
|
|
760
|
+
children.get(proc.ppid).push(proc.pid);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
764
|
+
finally {
|
|
765
|
+
try {
|
|
766
|
+
if (processes_2_1 && !processes_2_1.done && (_a = processes_2.return)) _a.call(processes_2);
|
|
767
|
+
}
|
|
768
|
+
finally { if (e_2) throw e_2.error; }
|
|
769
|
+
}
|
|
770
|
+
var protectedPids = new Set();
|
|
771
|
+
var addWithDescendants = function (pid) {
|
|
772
|
+
var e_4, _a;
|
|
773
|
+
if (protectedPids.has(pid)) {
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
protectedPids.add(pid);
|
|
777
|
+
try {
|
|
778
|
+
for (var _b = __values(children.get(pid) || []), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
779
|
+
var childPid = _c.value;
|
|
780
|
+
addWithDescendants(childPid);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
784
|
+
finally {
|
|
785
|
+
try {
|
|
786
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
787
|
+
}
|
|
788
|
+
finally { if (e_4) throw e_4.error; }
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
try {
|
|
792
|
+
for (var processes_3 = __values(processes), processes_3_1 = processes_3.next(); !processes_3_1.done; processes_3_1 = processes_3.next()) {
|
|
793
|
+
var proc = processes_3_1.value;
|
|
794
|
+
if (proc.args.includes('pm2-runtime') || proc.args.includes('/pm2/')) {
|
|
795
|
+
addWithDescendants(proc.pid);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
800
|
+
finally {
|
|
801
|
+
try {
|
|
802
|
+
if (processes_3_1 && !processes_3_1.done && (_b = processes_3.return)) _b.call(processes_3);
|
|
803
|
+
}
|
|
804
|
+
finally { if (e_3) throw e_3.error; }
|
|
805
|
+
}
|
|
806
|
+
var currentPid = process.pid;
|
|
807
|
+
while (currentPid && byPid.has(currentPid)) {
|
|
808
|
+
protectedPids.add(currentPid);
|
|
809
|
+
currentPid = byPid.get(currentPid).ppid;
|
|
810
|
+
}
|
|
811
|
+
return protectedPids;
|
|
812
|
+
};
|
|
813
|
+
ResolveIOMainServer.prototype.shouldReapStandaloneNodeProcess = function (proc, protectedPids) {
|
|
814
|
+
if (proc.pid === process.pid || proc.ppid !== 1 || protectedPids.has(proc.pid)) {
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
if (!this.isNodeProcess(proc) || !this.isSameUidProcess(proc.pid)) {
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
if (!this._standaloneNodeReaperIncludeSystemdServices && this.isProtectedSystemdServiceProcess(proc)) {
|
|
821
|
+
return false;
|
|
822
|
+
}
|
|
823
|
+
if (!this.isResolveIOAppProcess(proc)) {
|
|
824
|
+
return false;
|
|
825
|
+
}
|
|
826
|
+
if (proc.ageSeconds >= this._standaloneNodeReaperMinAgeSeconds) {
|
|
827
|
+
return true;
|
|
828
|
+
}
|
|
829
|
+
if (proc.ageSeconds < this._standaloneNodeReaperHighMinAgeSeconds || !this.hasHighStandaloneNodeResourceUsage(proc)) {
|
|
830
|
+
this.clearStandaloneNodeResourceHit(proc);
|
|
831
|
+
return false;
|
|
832
|
+
}
|
|
833
|
+
return this.recordStandaloneNodeResourceHit(proc) >= this._standaloneNodeReaperHighConsecutiveScans;
|
|
834
|
+
};
|
|
835
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperReason = function (proc) {
|
|
836
|
+
if (proc.ageSeconds >= this._standaloneNodeReaperMinAgeSeconds) {
|
|
837
|
+
return "orphan_age_seconds_gte_".concat(this._standaloneNodeReaperMinAgeSeconds);
|
|
838
|
+
}
|
|
839
|
+
var rssMb = proc.rssKb / 1024;
|
|
840
|
+
if (proc.cpuPct >= this._standaloneNodeReaperHighCpuPct && rssMb >= this._standaloneNodeReaperHighRssMb) {
|
|
841
|
+
return "orphan_high_cpu_and_rss_for_".concat(this._standaloneNodeReaperHighConsecutiveScans, "_scans");
|
|
842
|
+
}
|
|
843
|
+
if (proc.cpuPct >= this._standaloneNodeReaperHighCpuPct) {
|
|
844
|
+
return "orphan_high_cpu_for_".concat(this._standaloneNodeReaperHighConsecutiveScans, "_scans");
|
|
845
|
+
}
|
|
846
|
+
if (rssMb >= this._standaloneNodeReaperHighRssMb) {
|
|
847
|
+
return "orphan_high_rss_for_".concat(this._standaloneNodeReaperHighConsecutiveScans, "_scans");
|
|
848
|
+
}
|
|
849
|
+
return 'orphan_stale_node_process';
|
|
850
|
+
};
|
|
851
|
+
ResolveIOMainServer.prototype.isNodeProcess = function (proc) {
|
|
852
|
+
return proc.command === 'node' || proc.command.startsWith('node ') || proc.args === 'node' || proc.args.startsWith('node ');
|
|
853
|
+
};
|
|
854
|
+
ResolveIOMainServer.prototype.isResolveIOAppProcess = function (proc) {
|
|
855
|
+
var e_5, _a;
|
|
856
|
+
var normalizedArgs = proc.args || '';
|
|
857
|
+
var appDirs = this.resolveCurrentAppDirs();
|
|
858
|
+
try {
|
|
859
|
+
for (var appDirs_1 = __values(appDirs), appDirs_1_1 = appDirs_1.next(); !appDirs_1_1.done; appDirs_1_1 = appDirs_1.next()) {
|
|
860
|
+
var appDir = appDirs_1_1.value;
|
|
861
|
+
if (normalizedArgs.includes(appDir)) {
|
|
862
|
+
return true;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
867
|
+
finally {
|
|
868
|
+
try {
|
|
869
|
+
if (appDirs_1_1 && !appDirs_1_1.done && (_a = appDirs_1.return)) _a.call(appDirs_1);
|
|
870
|
+
}
|
|
871
|
+
finally { if (e_5) throw e_5.error; }
|
|
872
|
+
}
|
|
873
|
+
if (normalizedArgs.includes('server-app.js') && normalizedArgs.includes('require(')) {
|
|
874
|
+
return true;
|
|
875
|
+
}
|
|
876
|
+
var cwd = this.resolveProcessCwd(proc.pid);
|
|
877
|
+
return cwd !== null && appDirs.has(cwd) && /\b(index|server-app)\.js\b/.test(normalizedArgs);
|
|
878
|
+
};
|
|
879
|
+
ResolveIOMainServer.prototype.hasHighStandaloneNodeResourceUsage = function (proc) {
|
|
880
|
+
var rssMb = proc.rssKb / 1024;
|
|
881
|
+
return proc.cpuPct >= this._standaloneNodeReaperHighCpuPct || rssMb >= this._standaloneNodeReaperHighRssMb;
|
|
882
|
+
};
|
|
883
|
+
ResolveIOMainServer.prototype.recordStandaloneNodeResourceHit = function (proc) {
|
|
884
|
+
var signature = this.resolveStandaloneNodeProcessSignature(proc);
|
|
885
|
+
var now = Date.now();
|
|
886
|
+
var current = this._standaloneNodeReaperResourceHits.get(signature);
|
|
887
|
+
if (!current || (now - current.lastSeenMs) > (this._standaloneNodeReaperIntervalMs * 3)) {
|
|
888
|
+
this._standaloneNodeReaperResourceHits.set(signature, { count: 1, lastSeenMs: now });
|
|
889
|
+
return 1;
|
|
890
|
+
}
|
|
891
|
+
current.count += 1;
|
|
892
|
+
current.lastSeenMs = now;
|
|
893
|
+
return current.count;
|
|
894
|
+
};
|
|
895
|
+
ResolveIOMainServer.prototype.clearStandaloneNodeResourceHit = function (proc) {
|
|
896
|
+
this._standaloneNodeReaperResourceHits.delete(this.resolveStandaloneNodeProcessSignature(proc));
|
|
897
|
+
};
|
|
898
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeProcessSignature = function (proc) {
|
|
899
|
+
var cwd = this.resolveProcessCwd(proc.pid) || '';
|
|
900
|
+
return "".concat(cwd, "|").concat(proc.args);
|
|
901
|
+
};
|
|
902
|
+
ResolveIOMainServer.prototype.canReapStandaloneNodeSignature = function (signature) {
|
|
903
|
+
var now = Date.now();
|
|
904
|
+
var current = this._standaloneNodeReaperKillCounts.get(signature);
|
|
905
|
+
if (!current || (now - current.windowStartMs) > this._standaloneNodeReaperKillWindowMs) {
|
|
906
|
+
this._standaloneNodeReaperKillCounts.set(signature, { count: 0, windowStartMs: now });
|
|
907
|
+
this._standaloneNodeReaperSuppressedSignatures.delete(signature);
|
|
908
|
+
return true;
|
|
909
|
+
}
|
|
910
|
+
return current.count < this._standaloneNodeReaperMaxKillsPerSignature;
|
|
911
|
+
};
|
|
912
|
+
ResolveIOMainServer.prototype.recordStandaloneNodeReaperKill = function (signature) {
|
|
913
|
+
var now = Date.now();
|
|
914
|
+
var current = this._standaloneNodeReaperKillCounts.get(signature);
|
|
915
|
+
if (!current || (now - current.windowStartMs) > this._standaloneNodeReaperKillWindowMs) {
|
|
916
|
+
this._standaloneNodeReaperKillCounts.set(signature, { count: 1, windowStartMs: now });
|
|
917
|
+
this._standaloneNodeReaperSuppressedSignatures.delete(signature);
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
current.count += 1;
|
|
921
|
+
};
|
|
922
|
+
ResolveIOMainServer.prototype.logStandaloneNodeReaperSuppressed = function (proc, signature) {
|
|
923
|
+
if (this._standaloneNodeReaperSuppressedSignatures.has(signature)) {
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
this._standaloneNodeReaperSuppressedSignatures.add(signature);
|
|
927
|
+
console.warn(new Date(), '[Standalone Node Reaper] suppressing recurring stale node process', {
|
|
928
|
+
pid: proc.pid,
|
|
929
|
+
ppid: proc.ppid,
|
|
930
|
+
ageSeconds: proc.ageSeconds,
|
|
931
|
+
cpuPct: proc.cpuPct,
|
|
932
|
+
rssMb: (0, common_1.round)(proc.rssKb / 1024),
|
|
933
|
+
maxKillsPerSignature: this._standaloneNodeReaperMaxKillsPerSignature,
|
|
934
|
+
killWindowMs: this._standaloneNodeReaperKillWindowMs,
|
|
935
|
+
command: proc.args
|
|
936
|
+
});
|
|
937
|
+
};
|
|
938
|
+
ResolveIOMainServer.prototype.resolveCurrentAppDirs = function () {
|
|
939
|
+
var e_6, _a;
|
|
940
|
+
var _b;
|
|
941
|
+
var dirs = new Set();
|
|
942
|
+
try {
|
|
943
|
+
for (var _c = __values([process.cwd(), (_b = resolveio_server_app_1.ResolveIOServer.getClientDir) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)]), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
944
|
+
var value = _d.value;
|
|
945
|
+
if (!value) {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
var resolved = this.safeRealpath(value);
|
|
949
|
+
if (resolved) {
|
|
950
|
+
dirs.add(resolved);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
955
|
+
finally {
|
|
956
|
+
try {
|
|
957
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
958
|
+
}
|
|
959
|
+
finally { if (e_6) throw e_6.error; }
|
|
960
|
+
}
|
|
961
|
+
return dirs;
|
|
962
|
+
};
|
|
963
|
+
ResolveIOMainServer.prototype.resolveProcessCwd = function (pid) {
|
|
964
|
+
return this.safeRealpath("/proc/".concat(pid, "/cwd"));
|
|
965
|
+
};
|
|
966
|
+
ResolveIOMainServer.prototype.safeRealpath = function (value) {
|
|
967
|
+
try {
|
|
968
|
+
return fs.realpathSync(value);
|
|
969
|
+
}
|
|
970
|
+
catch (_a) {
|
|
971
|
+
return null;
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
ResolveIOMainServer.prototype.isSameUidProcess = function (pid) {
|
|
975
|
+
if (typeof process.getuid !== 'function') {
|
|
976
|
+
return true;
|
|
977
|
+
}
|
|
978
|
+
try {
|
|
979
|
+
var status_1 = fs.readFileSync("/proc/".concat(pid, "/status"), 'utf8');
|
|
980
|
+
var uidLine = status_1.split('\n').find(function (line) { return line.startsWith('Uid:'); });
|
|
981
|
+
if (!uidLine) {
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
var uid = parseInt(uidLine.split(/\s+/)[1], 10);
|
|
985
|
+
return uid === process.getuid();
|
|
986
|
+
}
|
|
987
|
+
catch (_a) {
|
|
988
|
+
return false;
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
ResolveIOMainServer.prototype.isProtectedSystemdServiceProcess = function (proc) {
|
|
992
|
+
var serviceName = this.resolveSystemdServiceName(proc.pid);
|
|
993
|
+
if (!serviceName) {
|
|
994
|
+
return false;
|
|
995
|
+
}
|
|
996
|
+
return /\bindex\.js\b/.test(proc.args);
|
|
997
|
+
};
|
|
998
|
+
ResolveIOMainServer.prototype.resolveSystemdServiceName = function (pid) {
|
|
999
|
+
try {
|
|
1000
|
+
var cgroup = fs.readFileSync("/proc/".concat(pid, "/cgroup"), 'utf8');
|
|
1001
|
+
var serviceLine = cgroup.split('\n').find(function (line) { return line.includes('/system.slice/') && line.includes('.service'); });
|
|
1002
|
+
if (!serviceLine) {
|
|
1003
|
+
return null;
|
|
1004
|
+
}
|
|
1005
|
+
var match = serviceLine.match(/\/system\.slice\/([^/]+\.service)/);
|
|
1006
|
+
return match ? match[1] : null;
|
|
1007
|
+
}
|
|
1008
|
+
catch (_a) {
|
|
1009
|
+
return null;
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
513
1012
|
ResolveIOMainServer.prototype.shutdownNetworkServers = function () {
|
|
514
1013
|
return __awaiter(this, void 0, void 0, function () {
|
|
515
1014
|
return __generator(this, function (_a) {
|
|
@@ -665,7 +1164,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
665
1164
|
return;
|
|
666
1165
|
}
|
|
667
1166
|
this._app.use(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
668
|
-
var appId, appDoc, allowedHosts, controlHosts, requestHost, originHeader, originHost, expectedToken, providedToken,
|
|
1167
|
+
var appId, appDoc, allowedHosts, controlHosts, requestHost, originHeader, originHost, expectedToken, providedToken, error_6;
|
|
669
1168
|
var _a, _b, _c;
|
|
670
1169
|
return __generator(this, function (_d) {
|
|
671
1170
|
switch (_d.label) {
|
|
@@ -748,11 +1247,11 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
748
1247
|
next();
|
|
749
1248
|
return [3 /*break*/, 4];
|
|
750
1249
|
case 3:
|
|
751
|
-
|
|
752
|
-
console.error(new Date(), '[DynamicAppGateway] middleware failure',
|
|
1250
|
+
error_6 = _d.sent();
|
|
1251
|
+
console.error(new Date(), '[DynamicAppGateway] middleware failure', error_6);
|
|
753
1252
|
res.status(500).send(JSON.stringify({
|
|
754
1253
|
error: true,
|
|
755
|
-
result: (
|
|
1254
|
+
result: (error_6 === null || error_6 === void 0 ? void 0 : error_6.message) || 'Dynamic app gateway error.'
|
|
756
1255
|
}));
|
|
757
1256
|
return [3 /*break*/, 4];
|
|
758
1257
|
case 4: return [2 /*return*/];
|
|
@@ -792,7 +1291,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
792
1291
|
return "".concat(parts[2] || '').trim();
|
|
793
1292
|
};
|
|
794
1293
|
ResolveIOMainServer.prototype.resolveDynamicAppGatewayToken = function (req) {
|
|
795
|
-
var
|
|
1294
|
+
var e_7, _a, e_8, _b, e_9, _c;
|
|
796
1295
|
var _d, _e, _f, _g, _h;
|
|
797
1296
|
var authHeader = this.normalizeHeaderValue(((_d = req.headers) === null || _d === void 0 ? void 0 : _d.authorization) || ((_e = req.headers) === null || _e === void 0 ? void 0 : _e.Authorization));
|
|
798
1297
|
if (authHeader) {
|
|
@@ -815,12 +1314,12 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
815
1314
|
}
|
|
816
1315
|
}
|
|
817
1316
|
}
|
|
818
|
-
catch (
|
|
1317
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
819
1318
|
finally {
|
|
820
1319
|
try {
|
|
821
1320
|
if (headerCandidates_1_1 && !headerCandidates_1_1.done && (_a = headerCandidates_1.return)) _a.call(headerCandidates_1);
|
|
822
1321
|
}
|
|
823
|
-
finally { if (
|
|
1322
|
+
finally { if (e_7) throw e_7.error; }
|
|
824
1323
|
}
|
|
825
1324
|
var body = req.body || {};
|
|
826
1325
|
var query = req.query || {};
|
|
@@ -834,12 +1333,12 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
834
1333
|
}
|
|
835
1334
|
}
|
|
836
1335
|
}
|
|
837
|
-
catch (
|
|
1336
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
838
1337
|
finally {
|
|
839
1338
|
try {
|
|
840
1339
|
if (bodyCandidates_1_1 && !bodyCandidates_1_1.done && (_b = bodyCandidates_1.return)) _b.call(bodyCandidates_1);
|
|
841
1340
|
}
|
|
842
|
-
finally { if (
|
|
1341
|
+
finally { if (e_8) throw e_8.error; }
|
|
843
1342
|
}
|
|
844
1343
|
var queryCandidates = [query.rioToken, query.rio_token, query.apiKey, query.token];
|
|
845
1344
|
try {
|
|
@@ -851,12 +1350,12 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
851
1350
|
}
|
|
852
1351
|
}
|
|
853
1352
|
}
|
|
854
|
-
catch (
|
|
1353
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
855
1354
|
finally {
|
|
856
1355
|
try {
|
|
857
1356
|
if (queryCandidates_1_1 && !queryCandidates_1_1.done && (_c = queryCandidates_1.return)) _c.call(queryCandidates_1);
|
|
858
1357
|
}
|
|
859
|
-
finally { if (
|
|
1358
|
+
finally { if (e_9) throw e_9.error; }
|
|
860
1359
|
}
|
|
861
1360
|
return '';
|
|
862
1361
|
};
|
|
@@ -908,7 +1407,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
908
1407
|
return normalized === 'localhost' || normalized === '127.0.0.1' || normalized === '::1';
|
|
909
1408
|
};
|
|
910
1409
|
ResolveIOMainServer.prototype.resolveDynamicAppControlHosts = function () {
|
|
911
|
-
var
|
|
1410
|
+
var e_10, _a;
|
|
912
1411
|
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
913
1412
|
var hosts = new Set();
|
|
914
1413
|
var candidates = [
|
|
@@ -931,17 +1430,17 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
931
1430
|
}
|
|
932
1431
|
}
|
|
933
1432
|
}
|
|
934
|
-
catch (
|
|
1433
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
935
1434
|
finally {
|
|
936
1435
|
try {
|
|
937
1436
|
if (candidates_1_1 && !candidates_1_1.done && (_a = candidates_1.return)) _a.call(candidates_1);
|
|
938
1437
|
}
|
|
939
|
-
finally { if (
|
|
1438
|
+
finally { if (e_10) throw e_10.error; }
|
|
940
1439
|
}
|
|
941
1440
|
return hosts;
|
|
942
1441
|
};
|
|
943
1442
|
ResolveIOMainServer.prototype.resolveDynamicAppAllowedHosts = function (appDoc) {
|
|
944
|
-
var
|
|
1443
|
+
var e_11, _a;
|
|
945
1444
|
var hosts = new Set();
|
|
946
1445
|
var candidates = [
|
|
947
1446
|
appDoc === null || appDoc === void 0 ? void 0 : appDoc.domain,
|
|
@@ -959,12 +1458,12 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
959
1458
|
}
|
|
960
1459
|
}
|
|
961
1460
|
}
|
|
962
|
-
catch (
|
|
1461
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
963
1462
|
finally {
|
|
964
1463
|
try {
|
|
965
1464
|
if (candidates_2_1 && !candidates_2_1.done && (_a = candidates_2.return)) _a.call(candidates_2);
|
|
966
1465
|
}
|
|
967
|
-
finally { if (
|
|
1466
|
+
finally { if (e_11) throw e_11.error; }
|
|
968
1467
|
}
|
|
969
1468
|
return hosts;
|
|
970
1469
|
};
|
|
@@ -1480,7 +1979,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1480
1979
|
}
|
|
1481
1980
|
});
|
|
1482
1981
|
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
1483
|
-
var socketData, usedBinary, bufferPayload, decodeResult, decodeResult, decodeResult, view, decodeResult,
|
|
1982
|
+
var socketData, usedBinary, bufferPayload, decodeResult, decodeResult, decodeResult, view, decodeResult, e_12, correlationId, context;
|
|
1484
1983
|
return __generator(this, function (_a) {
|
|
1485
1984
|
switch (_a.label) {
|
|
1486
1985
|
case 0:
|
|
@@ -1528,15 +2027,15 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1528
2027
|
}
|
|
1529
2028
|
return [3 /*break*/, 4];
|
|
1530
2029
|
case 2:
|
|
1531
|
-
|
|
1532
|
-
console.log('Error - WS message parse',
|
|
2030
|
+
e_12 = _a.sent();
|
|
2031
|
+
console.log('Error - WS message parse', e_12);
|
|
1533
2032
|
correlationId = (0, common_1.objectIdHexString)();
|
|
1534
2033
|
context = {
|
|
1535
2034
|
rawBinary: bufferPayload ? bufferPayload.toString('base64') : undefined,
|
|
1536
2035
|
rawMessage: typeof message === 'string' ? message : undefined,
|
|
1537
|
-
error:
|
|
2036
|
+
error: e_12 instanceof Error ? { name: e_12.name, message: e_12.message, stack: e_12.stack } : e_12
|
|
1538
2037
|
};
|
|
1539
|
-
return [4 /*yield*/, this.reportServerError('SERVER - JSON Parse Error - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, context, { context: 'websocket-message-parse' }, 'error',
|
|
2038
|
+
return [4 /*yield*/, this.reportServerError('SERVER - JSON Parse Error - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, context, { context: 'websocket-message-parse' }, 'error', e_12 instanceof Error ? e_12.stack : undefined)];
|
|
1540
2039
|
case 3:
|
|
1541
2040
|
_a.sent();
|
|
1542
2041
|
return [2 /*return*/];
|
|
@@ -1578,7 +2077,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1578
2077
|
// Do not block message handler registration on DB write; this avoids losing
|
|
1579
2078
|
// very-early subscription messages sent immediately after websocket open.
|
|
1580
2079
|
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1581
|
-
var
|
|
2080
|
+
var error_7;
|
|
1582
2081
|
return __generator(this, function (_a) {
|
|
1583
2082
|
switch (_a.label) {
|
|
1584
2083
|
case 0:
|
|
@@ -1588,13 +2087,13 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1588
2087
|
_a.sent();
|
|
1589
2088
|
return [3 /*break*/, 3];
|
|
1590
2089
|
case 2:
|
|
1591
|
-
|
|
1592
|
-
console.error(new Date(), 'Error creating logged-in user', ws['id_socket'],
|
|
2090
|
+
error_7 = _a.sent();
|
|
2091
|
+
console.error(new Date(), 'Error creating logged-in user', ws['id_socket'], error_7);
|
|
1593
2092
|
this.logConnectDebug('Create logged-in user failed', {
|
|
1594
2093
|
id_socket: ws['id_socket'],
|
|
1595
2094
|
id_user: ws['id_user'],
|
|
1596
2095
|
user: ws['user'],
|
|
1597
|
-
error: (
|
|
2096
|
+
error: (error_7 === null || error_7 === void 0 ? void 0 : error_7.message) || error_7
|
|
1598
2097
|
});
|
|
1599
2098
|
return [3 /*break*/, 3];
|
|
1600
2099
|
case 3: return [2 /*return*/];
|
|
@@ -1608,8 +2107,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1608
2107
|
}); });
|
|
1609
2108
|
// Keep alive timer
|
|
1610
2109
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1611
|
-
var _a, _b, ws,
|
|
1612
|
-
var
|
|
2110
|
+
var _a, _b, ws, e_13_1;
|
|
2111
|
+
var e_13, _c;
|
|
1613
2112
|
return __generator(this, function (_d) {
|
|
1614
2113
|
switch (_d.label) {
|
|
1615
2114
|
case 0:
|
|
@@ -1650,14 +2149,14 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1650
2149
|
return [3 /*break*/, 1];
|
|
1651
2150
|
case 9: return [3 /*break*/, 12];
|
|
1652
2151
|
case 10:
|
|
1653
|
-
|
|
1654
|
-
|
|
2152
|
+
e_13_1 = _d.sent();
|
|
2153
|
+
e_13 = { error: e_13_1 };
|
|
1655
2154
|
return [3 /*break*/, 12];
|
|
1656
2155
|
case 11:
|
|
1657
2156
|
try {
|
|
1658
2157
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1659
2158
|
}
|
|
1660
|
-
finally { if (
|
|
2159
|
+
finally { if (e_13) throw e_13.error; }
|
|
1661
2160
|
return [7 /*endfinally*/];
|
|
1662
2161
|
case 12: return [2 /*return*/];
|
|
1663
2162
|
}
|
|
@@ -1666,8 +2165,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1666
2165
|
};
|
|
1667
2166
|
ResolveIOMainServer.prototype.processSocketMessage = function (ws, socketData) {
|
|
1668
2167
|
return __awaiter(this, void 0, void 0, function () {
|
|
1669
|
-
var socketData_1, socketData_1_1, message,
|
|
1670
|
-
var
|
|
2168
|
+
var socketData_1, socketData_1_1, message, e_14_1;
|
|
2169
|
+
var e_14, _a;
|
|
1671
2170
|
return __generator(this, function (_b) {
|
|
1672
2171
|
switch (_b.label) {
|
|
1673
2172
|
case 0:
|
|
@@ -1711,14 +2210,14 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1711
2210
|
return [3 /*break*/, 2];
|
|
1712
2211
|
case 5: return [3 /*break*/, 8];
|
|
1713
2212
|
case 6:
|
|
1714
|
-
|
|
1715
|
-
|
|
2213
|
+
e_14_1 = _b.sent();
|
|
2214
|
+
e_14 = { error: e_14_1 };
|
|
1716
2215
|
return [3 /*break*/, 8];
|
|
1717
2216
|
case 7:
|
|
1718
2217
|
try {
|
|
1719
2218
|
if (socketData_1_1 && !socketData_1_1.done && (_a = socketData_1.return)) _a.call(socketData_1);
|
|
1720
2219
|
}
|
|
1721
|
-
finally { if (
|
|
2220
|
+
finally { if (e_14) throw e_14.error; }
|
|
1722
2221
|
return [7 /*endfinally*/];
|
|
1723
2222
|
case 8: return [2 /*return*/];
|
|
1724
2223
|
}
|
|
@@ -1851,6 +2350,92 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1851
2350
|
var raw = (_a = process.env.TIMER_DEBUG_LOG_LIMIT) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config['TIMER_DEBUG_LOG_LIMIT'];
|
|
1852
2351
|
return this.parsePositiveInt(raw, this._timerDebugLogLimit);
|
|
1853
2352
|
};
|
|
2353
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperEnabled = function () {
|
|
2354
|
+
var _a, _b, _c;
|
|
2355
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2356
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_ENABLED) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_ENABLED) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_ENABLED']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_ENABLED'];
|
|
2357
|
+
var configured = this.parseOptionalBoolean(raw);
|
|
2358
|
+
if (configured !== null) {
|
|
2359
|
+
return configured;
|
|
2360
|
+
}
|
|
2361
|
+
return this.isPm2ManagedRuntime() && !this.isLocalRuntime();
|
|
2362
|
+
};
|
|
2363
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperIntervalMs = function () {
|
|
2364
|
+
var _a, _b, _c;
|
|
2365
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2366
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_INTERVAL_MS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_INTERVAL_MS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_INTERVAL_MS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_INTERVAL_MS'];
|
|
2367
|
+
return this.parsePositiveInt(raw, this._standaloneNodeReaperIntervalMs);
|
|
2368
|
+
};
|
|
2369
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperMinAgeSeconds = function () {
|
|
2370
|
+
var _a, _b, _c;
|
|
2371
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2372
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_MIN_AGE_SECONDS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_MIN_AGE_SECONDS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_MIN_AGE_SECONDS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_MIN_AGE_SECONDS'];
|
|
2373
|
+
return this.parsePositiveInt(raw, this._standaloneNodeReaperMinAgeSeconds);
|
|
2374
|
+
};
|
|
2375
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperMaxKillsPerSignature = function () {
|
|
2376
|
+
var _a, _b, _c;
|
|
2377
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2378
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_MAX_KILLS_PER_SIGNATURE) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_MAX_KILLS_PER_SIGNATURE) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_MAX_KILLS_PER_SIGNATURE']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_MAX_KILLS_PER_SIGNATURE'];
|
|
2379
|
+
return this.parsePositiveInt(raw, this._standaloneNodeReaperMaxKillsPerSignature);
|
|
2380
|
+
};
|
|
2381
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperKillWindowMs = function () {
|
|
2382
|
+
var _a, _b, _c;
|
|
2383
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2384
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_KILL_WINDOW_MS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_KILL_WINDOW_MS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_KILL_WINDOW_MS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_KILL_WINDOW_MS'];
|
|
2385
|
+
return this.parsePositiveInt(raw, this._standaloneNodeReaperKillWindowMs);
|
|
2386
|
+
};
|
|
2387
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperIncludeSystemdServices = function () {
|
|
2388
|
+
var _a, _b, _c;
|
|
2389
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2390
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_INCLUDE_SYSTEMD_SERVICES) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_INCLUDE_SYSTEMD_SERVICES) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_INCLUDE_SYSTEMD_SERVICES']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_INCLUDE_SYSTEMD_SERVICES'];
|
|
2391
|
+
return this.parseDebugFlag(raw);
|
|
2392
|
+
};
|
|
2393
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperHighCpuPct = function () {
|
|
2394
|
+
var _a, _b, _c;
|
|
2395
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2396
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_CPU_PCT) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_HIGH_CPU_PCT) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_CPU_PCT']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_HIGH_CPU_PCT'];
|
|
2397
|
+
return this.parsePositiveFloat(raw, this._standaloneNodeReaperHighCpuPct);
|
|
2398
|
+
};
|
|
2399
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperHighRssMb = function () {
|
|
2400
|
+
var _a, _b, _c;
|
|
2401
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2402
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_RSS_MB) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_HIGH_RSS_MB) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_RSS_MB']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_HIGH_RSS_MB'];
|
|
2403
|
+
return this.parsePositiveFloat(raw, this._standaloneNodeReaperHighRssMb);
|
|
2404
|
+
};
|
|
2405
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperHighMinAgeSeconds = function () {
|
|
2406
|
+
var _a, _b, _c;
|
|
2407
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2408
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_MIN_AGE_SECONDS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_HIGH_MIN_AGE_SECONDS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_MIN_AGE_SECONDS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_HIGH_MIN_AGE_SECONDS'];
|
|
2409
|
+
return this.parsePositiveInt(raw, this._standaloneNodeReaperHighMinAgeSeconds);
|
|
2410
|
+
};
|
|
2411
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperHighConsecutiveScans = function () {
|
|
2412
|
+
var _a, _b, _c;
|
|
2413
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2414
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_CONSECUTIVE_SCANS) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_HIGH_CONSECUTIVE_SCANS) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_HIGH_CONSECUTIVE_SCANS']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_HIGH_CONSECUTIVE_SCANS'];
|
|
2415
|
+
return this.parsePositiveInt(raw, this._standaloneNodeReaperHighConsecutiveScans);
|
|
2416
|
+
};
|
|
2417
|
+
ResolveIOMainServer.prototype.resolveStandaloneNodeReaperDryRun = function () {
|
|
2418
|
+
var _a, _b, _c;
|
|
2419
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2420
|
+
var raw = (_c = (_b = (_a = process.env.RESOLVEIO_STANDALONE_NODE_REAPER_DRY_RUN) !== null && _a !== void 0 ? _a : process.env.STANDALONE_NODE_REAPER_DRY_RUN) !== null && _b !== void 0 ? _b : config === null || config === void 0 ? void 0 : config['RESOLVEIO_STANDALONE_NODE_REAPER_DRY_RUN']) !== null && _c !== void 0 ? _c : config === null || config === void 0 ? void 0 : config['STANDALONE_NODE_REAPER_DRY_RUN'];
|
|
2421
|
+
return this.parseDebugFlag(raw);
|
|
2422
|
+
};
|
|
2423
|
+
ResolveIOMainServer.prototype.isPm2ManagedRuntime = function () {
|
|
2424
|
+
return Boolean(process.env.pm_id
|
|
2425
|
+
|| process.env.PM2_HOME
|
|
2426
|
+
|| process.env.NODE_APP_INSTANCE
|
|
2427
|
+
|| "".concat(process.env._ || '').includes('pm2'));
|
|
2428
|
+
};
|
|
2429
|
+
ResolveIOMainServer.prototype.isPrimaryPm2Instance = function () {
|
|
2430
|
+
var appInstance = this.normalizeWorkerSelectorValue(process.env.NODE_APP_INSTANCE);
|
|
2431
|
+
return !appInstance || appInstance === '0';
|
|
2432
|
+
};
|
|
2433
|
+
ResolveIOMainServer.prototype.isLocalRuntime = function () {
|
|
2434
|
+
var config = resolveio_server_app_1.ResolveIOServer.getServerConfig ? resolveio_server_app_1.ResolveIOServer.getServerConfig() : null;
|
|
2435
|
+
var rootUrl = "".concat(process.env.ROOT_URL || (config === null || config === void 0 ? void 0 : config['ROOT_URL']) || '').trim().toLowerCase();
|
|
2436
|
+
var serverUrl = "".concat(process.env.SERVER_URL || (config === null || config === void 0 ? void 0 : config['SERVER_URL']) || '').trim().toLowerCase();
|
|
2437
|
+
return rootUrl.includes('localhost') || rootUrl.includes('127.0.0.1') || serverUrl.includes('localhost') || serverUrl.includes('127.0.0.1');
|
|
2438
|
+
};
|
|
1854
2439
|
ResolveIOMainServer.prototype.normalizeWorkerSelectorValue = function (value) {
|
|
1855
2440
|
if (value === null || value === undefined) {
|
|
1856
2441
|
return null;
|
|
@@ -2281,8 +2866,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
2281
2866
|
};
|
|
2282
2867
|
ResolveIOMainServer.prototype.disconnectUserSocketsFromDifferentIps = function (idUser, incomingIp) {
|
|
2283
2868
|
return __awaiter(this, void 0, void 0, function () {
|
|
2284
|
-
var normalizedUser, normalizedIncomingIp, userSockets, disconnected, userSockets_1, userSockets_1_1, existingSocket, existingIp,
|
|
2285
|
-
var
|
|
2869
|
+
var normalizedUser, normalizedIncomingIp, userSockets, disconnected, userSockets_1, userSockets_1_1, existingSocket, existingIp, e_15_1;
|
|
2870
|
+
var e_15, _a;
|
|
2286
2871
|
return __generator(this, function (_b) {
|
|
2287
2872
|
switch (_b.label) {
|
|
2288
2873
|
case 0:
|
|
@@ -2330,14 +2915,14 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
2330
2915
|
return [3 /*break*/, 2];
|
|
2331
2916
|
case 5: return [3 /*break*/, 8];
|
|
2332
2917
|
case 6:
|
|
2333
|
-
|
|
2334
|
-
|
|
2918
|
+
e_15_1 = _b.sent();
|
|
2919
|
+
e_15 = { error: e_15_1 };
|
|
2335
2920
|
return [3 /*break*/, 8];
|
|
2336
2921
|
case 7:
|
|
2337
2922
|
try {
|
|
2338
2923
|
if (userSockets_1_1 && !userSockets_1_1.done && (_a = userSockets_1.return)) _a.call(userSockets_1);
|
|
2339
2924
|
}
|
|
2340
|
-
finally { if (
|
|
2925
|
+
finally { if (e_15) throw e_15.error; }
|
|
2341
2926
|
return [7 /*endfinally*/];
|
|
2342
2927
|
case 8: return [2 /*return*/, disconnected];
|
|
2343
2928
|
}
|
|
@@ -2718,7 +3303,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
2718
3303
|
});
|
|
2719
3304
|
}
|
|
2720
3305
|
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2721
|
-
var
|
|
3306
|
+
var error_8;
|
|
2722
3307
|
return __generator(this, function (_a) {
|
|
2723
3308
|
switch (_a.label) {
|
|
2724
3309
|
case 0:
|
|
@@ -2728,8 +3313,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
2728
3313
|
_a.sent();
|
|
2729
3314
|
return [3 /*break*/, 3];
|
|
2730
3315
|
case 2:
|
|
2731
|
-
|
|
2732
|
-
console.error(new Date(), 'AI execution run failed:',
|
|
3316
|
+
error_8 = _a.sent();
|
|
3317
|
+
console.error(new Date(), 'AI execution run failed:', error_8);
|
|
2733
3318
|
return [3 /*break*/, 3];
|
|
2734
3319
|
case 3: return [2 /*return*/];
|
|
2735
3320
|
}
|