From eacd439233812f48a184414e788d4576c9e6d425 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Fri, 19 Sep 2025 01:34:39 +0800 Subject: [PATCH] Fix SSH connection stability in file manager - Enable SSH keepalive mechanism (keepaliveCountMax: 0 -> 3) - Set proper ready timeout (0 -> 60000ms) - Implement session cleanup with 10-minute timeout - Add scheduleSessionCleanup call on connection ready Resolves random disconnections every 2-3 minutes during file editing. --- src/backend/ssh/file-manager.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/ssh/file-manager.ts b/src/backend/ssh/file-manager.ts index a17f76e8..f96611a3 100644 --- a/src/backend/ssh/file-manager.ts +++ b/src/backend/ssh/file-manager.ts @@ -85,7 +85,14 @@ function cleanupSession(sessionId: string) { function scheduleSessionCleanup(sessionId: string) { const session = sshSessions[sessionId]; if (session) { + // Clear existing timeout if (session.timeout) clearTimeout(session.timeout); + + // Set new timeout for 10 minutes of inactivity + session.timeout = setTimeout(() => { + fileLogger.info(`Cleaning up inactive SSH session: ${sessionId}`); + cleanupSession(sessionId); + }, 10 * 60 * 1000); // 10 minutes } } @@ -176,9 +183,9 @@ app.post("/ssh/file_manager/ssh/connect", async (req, res) => { host: ip, port: port || 22, username, - readyTimeout: 0, + readyTimeout: 60000, keepaliveInterval: 30000, - keepaliveCountMax: 0, + keepaliveCountMax: 3, algorithms: { kex: [ "diffie-hellman-group14-sha256", @@ -259,6 +266,7 @@ app.post("/ssh/file_manager/ssh/connect", async (req, res) => { isConnected: true, lastActive: Date.now(), }; + scheduleSessionCleanup(sessionId); res.json({ status: "success", message: "SSH connection established" }); });