mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-07 04:22:16 +00:00
fix(wss): enhance error handling and logging for SSH connections in WebSocket server
This commit is contained in:
@@ -58,7 +58,12 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
|||||||
`docker exec -it -w / ${containerId} ${activeWay}`,
|
`docker exec -it -w / ${containerId} ${activeWay}`,
|
||||||
{ pty: true },
|
{ pty: true },
|
||||||
(err, stream) => {
|
(err, stream) => {
|
||||||
if (err) throw err;
|
if (err) {
|
||||||
|
console.error("SSH exec error:", err);
|
||||||
|
ws.close();
|
||||||
|
conn.end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.on("close", (code: number, _signal: string) => {
|
.on("close", (code: number, _signal: string) => {
|
||||||
@@ -93,10 +98,20 @@ export const setupDockerContainerTerminalWebSocketServer = (
|
|||||||
|
|
||||||
ws.on("close", () => {
|
ws.on("close", () => {
|
||||||
stream.end();
|
stream.end();
|
||||||
|
// Ensure SSH connection is closed when WebSocket closes
|
||||||
|
conn.end();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
.on("error", (err) => {
|
||||||
|
console.error("SSH connection error:", err);
|
||||||
|
if (ws.readyState === ws.OPEN) {
|
||||||
|
ws.send(`SSH error: ${err.message}`);
|
||||||
|
ws.close();
|
||||||
|
}
|
||||||
|
conn.end();
|
||||||
|
})
|
||||||
.connect({
|
.connect({
|
||||||
host: server.ipAddress,
|
host: server.ipAddress,
|
||||||
port: server.port,
|
port: server.port,
|
||||||
|
|||||||
Reference in New Issue
Block a user