mirror of
https://github.com/Dasemu/remote-mcp-manager.git
synced 2026-11-26 15:26:27 +00:00
fix: bound memory and sockets in the manager to prevent host-wide OOM
- proxy: inactivity timeouts and a cap on concurrent requests (503 beyond it) - docker: cache/coalesce container IP lookups and time out inspect calls - sessions: SQLite-backed store instead of the leaking MemoryStore - memory guard: exit when heap+external passes MANAGER_MEMORY_LIMIT_MB so the restart policy replaces the process before the host swaps - builds: serialize them and time out hung git/nixpacks processes - redeploy with rebuild no longer deploys the old image after a failed build - /health reports memory and in-flight proxy requests; handle SIGTERM Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
05ad174f90
commit
eb24e21df7
14 files changed
+371
-12
No files matched your search
@@ -0,0 +1,40 @@
|
||||
const MB = 1024 * 1024;
|
||||
|
||||
export interface MemorySample {
|
||||
heapUsed: number;
|
||||
external: number;
|
||||
}
|
||||
|
||||
/** Heap + external, not RSS: RSS drops when the kernel swaps pages out, which hides a leak on a swapping host. */
|
||||
export function usedMb(sample: MemorySample): number {
|
||||
return (sample.heapUsed + sample.external) / MB;
|
||||
}
|
||||
|
||||
export function isOverLimit(sample: MemorySample, limitMb: number): boolean {
|
||||
return limitMb > 0 && usedMb(sample) > limitMb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls the process's own memory and calls `onExceeded` once it passes `limitMb`. The caller is
|
||||
* expected to exit so the container restart policy replaces a bloated process with a fresh one
|
||||
* *before* the host starts swapping and every other container on it degrades.
|
||||
*/
|
||||
export function startMemoryGuard(opts: {
|
||||
limitMb: number;
|
||||
intervalMs?: number;
|
||||
sample?: () => MemorySample;
|
||||
onExceeded: (usedMb: number) => void;
|
||||
}): NodeJS.Timeout | undefined {
|
||||
if (opts.limitMb <= 0) return undefined;
|
||||
const sample = opts.sample ?? (() => process.memoryUsage());
|
||||
let fired = false;
|
||||
const timer = setInterval(() => {
|
||||
const current = sample();
|
||||
if (!fired && isOverLimit(current, opts.limitMb)) {
|
||||
fired = true;
|
||||
opts.onExceeded(usedMb(current));
|
||||
}
|
||||
}, opts.intervalMs ?? 30_000);
|
||||
timer.unref();
|
||||
return timer;
|
||||
}
|
||||
Reference in new issue
Block a user