mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(dokploy): terminate connections
This commit is contained in:
@@ -5,6 +5,11 @@ import { Client } from "ssh2";
|
|||||||
import { WebSocketServer } from "ws";
|
import { WebSocketServer } from "ws";
|
||||||
import { getShell } from "./utils";
|
import { getShell } from "./utils";
|
||||||
|
|
||||||
|
function heartbeat() {
|
||||||
|
// @ts-ignore
|
||||||
|
this.isAlive = true;
|
||||||
|
}
|
||||||
|
|
||||||
export const setupDockerContainerLogsWebSocketServer = (
|
export const setupDockerContainerLogsWebSocketServer = (
|
||||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||||
) => {
|
) => {
|
||||||
@@ -44,14 +49,10 @@ export const setupDockerContainerLogsWebSocketServer = (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pingInterval = setInterval(() => {
|
// @ts-ignore
|
||||||
if (ws.readyState === ws.OPEN) {
|
ws.isAlive = true;
|
||||||
ws.ping();
|
ws.on("error", console.error);
|
||||||
}
|
ws.on("pong", heartbeat);
|
||||||
}, 30000);
|
|
||||||
|
|
||||||
ws.on("close", () => clearInterval(pingInterval));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
const server = await findServerById(serverId);
|
const server = await findServerById(serverId);
|
||||||
@@ -147,4 +148,18 @@ export const setupDockerContainerLogsWebSocketServer = (
|
|||||||
ws.send(errorMessage);
|
ws.send(errorMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const interval = setInterval(function ping() {
|
||||||
|
for (const ws of wssTerm.clients) {
|
||||||
|
// @ts-ignore
|
||||||
|
if (ws.isAlive === false) return ws.terminate();
|
||||||
|
// @ts-ignore
|
||||||
|
ws.isAlive = false;
|
||||||
|
ws.ping();
|
||||||
|
}
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
|
wssTerm.on("close", function close() {
|
||||||
|
clearInterval(interval);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user