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.
This commit is contained in:
@@ -85,7 +85,14 @@ function cleanupSession(sessionId: string) {
|
|||||||
function scheduleSessionCleanup(sessionId: string) {
|
function scheduleSessionCleanup(sessionId: string) {
|
||||||
const session = sshSessions[sessionId];
|
const session = sshSessions[sessionId];
|
||||||
if (session) {
|
if (session) {
|
||||||
|
// Clear existing timeout
|
||||||
if (session.timeout) clearTimeout(session.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,
|
host: ip,
|
||||||
port: port || 22,
|
port: port || 22,
|
||||||
username,
|
username,
|
||||||
readyTimeout: 0,
|
readyTimeout: 60000,
|
||||||
keepaliveInterval: 30000,
|
keepaliveInterval: 30000,
|
||||||
keepaliveCountMax: 0,
|
keepaliveCountMax: 3,
|
||||||
algorithms: {
|
algorithms: {
|
||||||
kex: [
|
kex: [
|
||||||
"diffie-hellman-group14-sha256",
|
"diffie-hellman-group14-sha256",
|
||||||
@@ -259,6 +266,7 @@ app.post("/ssh/file_manager/ssh/connect", async (req, res) => {
|
|||||||
isConnected: true,
|
isConnected: true,
|
||||||
lastActive: Date.now(),
|
lastActive: Date.now(),
|
||||||
};
|
};
|
||||||
|
scheduleSessionCleanup(sessionId);
|
||||||
res.json({ status: "success", message: "SSH connection established" });
|
res.json({ status: "success", message: "SSH connection established" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user