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:
parent
9872c4fee3
commit
ae5df82887
@ -5,6 +5,11 @@ import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
function heartbeat() {
|
||||
// @ts-ignore
|
||||
this.isAlive = true;
|
||||
}
|
||||
|
||||
export const setupDockerContainerLogsWebSocketServer = (
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||
) => {
|
||||
@ -44,14 +49,10 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
return;
|
||||
}
|
||||
|
||||
const pingInterval = setInterval(() => {
|
||||
if (ws.readyState === ws.OPEN) {
|
||||
ws.ping();
|
||||
}
|
||||
}, 30000);
|
||||
|
||||
ws.on("close", () => clearInterval(pingInterval));
|
||||
|
||||
// @ts-ignore
|
||||
ws.isAlive = true;
|
||||
ws.on("error", console.error);
|
||||
ws.on("pong", heartbeat);
|
||||
try {
|
||||
if (serverId) {
|
||||
const server = await findServerById(serverId);
|
||||
@ -147,4 +148,18 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
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);
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user