fix: close WebSocket and auto-remove session on SSH connect failure
When SSH connection fails, close the WebSocket immediately and auto-remove the pending session after 3 seconds so the user sees the error message before the panel clears. Prevents stuck sessions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6262ab6e7e
commit
2216ee79aa
@ -84,12 +84,23 @@ export function useTerminal() {
|
|||||||
break
|
break
|
||||||
case 'error':
|
case 'error':
|
||||||
term.write(`\r\n\x1b[31mError: ${msg.message}\x1b[0m\r\n`)
|
term.write(`\r\n\x1b[31mError: ${msg.message}\x1b[0m\r\n`)
|
||||||
|
term.write('\x1b[33mPress any key to close this session.\x1b[0m\r\n')
|
||||||
|
// Mark this connection as failed so onData closes it
|
||||||
|
ws?.close()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.onclose = () => {
|
ws.onclose = () => {
|
||||||
term.write('\r\n\x1b[33mConnection closed.\x1b[0m\r\n')
|
term.write('\r\n\x1b[33mConnection closed.\x1b[0m\r\n')
|
||||||
|
// Clean up pending session if connection never succeeded
|
||||||
|
if (pendingSessionId.startsWith('pending-')) {
|
||||||
|
const session = sessions.sessions.find(s => s.id === pendingSessionId)
|
||||||
|
if (session) {
|
||||||
|
// Session was never replaced with a real one — remove after short delay so user sees the error
|
||||||
|
setTimeout(() => sessions.removeSession(pendingSessionId), 3000)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Terminal input → WebSocket
|
// Terminal input → WebSocket
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user