fix(connection): keep SSH tunnels alive
This commit is contained in:
1 parent
cc9c174fc5
commit
6b8b2a1009
6 files changed
+37
-11
No files matched your search
@@ -1572,7 +1572,7 @@ export default {
|
|||||||
showColumnCommentsInHeaderDescription: "Display table column comments directly below grid column names.",
|
showColumnCommentsInHeaderDescription: "Display table column comments directly below grid column names.",
|
||||||
compactColumnHeaderActions: "Compact column header tools",
|
compactColumnHeaderActions: "Compact column header tools",
|
||||||
compactColumnHeaderActionsDescription:
|
compactColumnHeaderActionsDescription:
|
||||||
"Move sort, formatter, and local filter tools into a more menu so column names get priority.",
|
"Move formatter and local filter tools into a more menu so column names get priority.",
|
||||||
sidebarActivation: "Sidebar activation",
|
sidebarActivation: "Sidebar activation",
|
||||||
sidebarActivationSingle: "Single click",
|
sidebarActivationSingle: "Single click",
|
||||||
sidebarActivationSingleDescription: "Open actionable sidebar items with one click.",
|
sidebarActivationSingleDescription: "Open actionable sidebar items with one click.",
|
||||||
|
|||||||
@@ -1464,7 +1464,7 @@ export default {
|
|||||||
"Muestra los comentarios de columnas directamente debajo del nombre de la columna.",
|
"Muestra los comentarios de columnas directamente debajo del nombre de la columna.",
|
||||||
compactColumnHeaderActions: "Compactar herramientas del encabezado",
|
compactColumnHeaderActions: "Compactar herramientas del encabezado",
|
||||||
compactColumnHeaderActionsDescription:
|
compactColumnHeaderActionsDescription:
|
||||||
"Mueve ordenar, formatear y filtrar a un menú de más acciones para priorizar el nombre de columna.",
|
"Mueve formatear y filtrar a un menú de más acciones para priorizar el nombre de columna.",
|
||||||
sidebarActivation: "Activación de la barra lateral",
|
sidebarActivation: "Activación de la barra lateral",
|
||||||
sidebarActivationSingle: "Un clic",
|
sidebarActivationSingle: "Un clic",
|
||||||
sidebarActivationSingleDescription: "Abrir elementos accionables de la barra lateral con un clic.",
|
sidebarActivationSingleDescription: "Abrir elementos accionables de la barra lateral con un clic.",
|
||||||
|
|||||||
@@ -1542,7 +1542,7 @@ export default {
|
|||||||
showColumnCommentsInHeader: "在字段名下方显示注释",
|
showColumnCommentsInHeader: "在字段名下方显示注释",
|
||||||
showColumnCommentsInHeaderDescription: "把表字段注释直接显示在结果表头字段名下方。",
|
showColumnCommentsInHeaderDescription: "把表字段注释直接显示在结果表头字段名下方。",
|
||||||
compactColumnHeaderActions: "收起字段表头工具",
|
compactColumnHeaderActions: "收起字段表头工具",
|
||||||
compactColumnHeaderActionsDescription: "将排序、格式化、本地筛选收进更多菜单,优先显示字段名称。",
|
compactColumnHeaderActionsDescription: "将格式化、本地筛选收进更多菜单,优先显示字段名称。",
|
||||||
sidebarActivation: "侧边栏打开方式",
|
sidebarActivation: "侧边栏打开方式",
|
||||||
sidebarActivationSingle: "单击打开",
|
sidebarActivationSingle: "单击打开",
|
||||||
sidebarActivationSingleDescription: "单击即可打开侧边栏中的可操作项目。",
|
sidebarActivationSingleDescription: "单击即可打开侧边栏中的可操作项目。",
|
||||||
|
|||||||
@@ -1541,7 +1541,7 @@ export default {
|
|||||||
showColumnCommentsInHeader: "在欄位名稱下方顯示註解",
|
showColumnCommentsInHeader: "在欄位名稱下方顯示註解",
|
||||||
showColumnCommentsInHeaderDescription: "直接在資料表格欄位名稱下方顯示資料表欄位註解。",
|
showColumnCommentsInHeaderDescription: "直接在資料表格欄位名稱下方顯示資料表欄位註解。",
|
||||||
compactColumnHeaderActions: "收起欄位表頭工具",
|
compactColumnHeaderActions: "收起欄位表頭工具",
|
||||||
compactColumnHeaderActionsDescription: "將排序、格式設定和本機篩選工具移到更多選單,讓欄位名稱優先顯示。",
|
compactColumnHeaderActionsDescription: "將格式設定和本機篩選工具移到更多選單,讓欄位名稱優先顯示。",
|
||||||
sidebarActivation: "側邊欄開啟方式",
|
sidebarActivation: "側邊欄開啟方式",
|
||||||
sidebarActivationSingle: "單擊開啟",
|
sidebarActivationSingle: "單擊開啟",
|
||||||
sidebarActivationSingleDescription: "單擊即可開啟側邊欄中的可操作項目。",
|
sidebarActivationSingleDescription: "單擊即可開啟側邊欄中的可操作項目。",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tokio::time::Duration;
|
use tokio::time::{Duration, MissedTickBehavior};
|
||||||
|
|
||||||
use crate::models::connection::SshTunnelConfig;
|
use crate::models::connection::SshTunnelConfig;
|
||||||
|
|
||||||
@@ -20,6 +20,10 @@ const INITIAL_RECONNECT_DELAY: Duration = Duration::from_secs(5);
|
|||||||
const MAX_RECONNECT_DELAY: Duration = Duration::from_secs(60);
|
const MAX_RECONNECT_DELAY: Duration = Duration::from_secs(60);
|
||||||
/// Maximum number of consecutive reconnect attempts before giving up.
|
/// Maximum number of consecutive reconnect attempts before giving up.
|
||||||
const MAX_RECONNECT_ATTEMPTS: u32 = 10;
|
const MAX_RECONNECT_ATTEMPTS: u32 = 10;
|
||||||
|
/// How often an idle local listener verifies that the SSH session still answers.
|
||||||
|
const IDLE_SESSION_CHECK_INTERVAL: Duration = Duration::from_secs(30);
|
||||||
|
/// Maximum time to wait for an explicit SSH ping response.
|
||||||
|
const IDLE_SESSION_PING_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
|
|
||||||
struct SshClient;
|
struct SshClient;
|
||||||
|
|
||||||
@@ -93,8 +97,32 @@ async fn connect_and_authenticate(
|
|||||||
/// Accept connections on the local listener and forward them through the SSH session.
|
/// Accept connections on the local listener and forward them through the SSH session.
|
||||||
/// Returns when the SSH session dies (listener error or session.is_closed()).
|
/// Returns when the SSH session dies (listener error or session.is_closed()).
|
||||||
async fn forward_loop(session: &Handle<SshClient>, listener: &TcpListener, remote_host: &str, remote_port: u16) {
|
async fn forward_loop(session: &Handle<SshClient>, listener: &TcpListener, remote_host: &str, remote_port: u16) {
|
||||||
|
let mut idle_check = tokio::time::interval(IDLE_SESSION_CHECK_INTERVAL);
|
||||||
|
idle_check.set_missed_tick_behavior(MissedTickBehavior::Delay);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (mut stream, peer_addr) = match listener.accept().await {
|
let accepted = tokio::select! {
|
||||||
|
result = listener.accept() => result,
|
||||||
|
_ = idle_check.tick() => {
|
||||||
|
if session.is_closed() {
|
||||||
|
log::warn!("SSH session closed while tunnel was idle");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
match tokio::time::timeout(IDLE_SESSION_PING_TIMEOUT, session.send_ping()).await {
|
||||||
|
Ok(Ok(())) => continue,
|
||||||
|
Ok(Err(e)) => {
|
||||||
|
log::warn!("SSH idle ping failed: {e}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
log::warn!("SSH idle ping timed out");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let (mut stream, peer_addr) = match accepted {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("SSH tunnel listener error: {e}");
|
log::error!("SSH tunnel listener error: {e}");
|
||||||
@@ -120,11 +148,7 @@ async fn forward_loop(session: &Handle<SshClient>, listener: &TcpListener, remot
|
|||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("SSH direct-tcpip failed: {e}");
|
log::error!("SSH direct-tcpip failed: {e}");
|
||||||
if session.is_closed() {
|
break;
|
||||||
log::warn!("SSH session closed after channel open failure");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -359,6 +359,7 @@ pub fn is_connection_error(err: &str) -> bool {
|
|||||||
|| lower.contains("not connected")
|
|| lower.contains("not connected")
|
||||||
|| lower.contains("end-of-file")
|
|| lower.contains("end-of-file")
|
||||||
|| lower.contains("idle")
|
|| lower.contains("idle")
|
||||||
|
|| lower.contains("communicating with the server")
|
||||||
|| is_os_connection_error(&lower)
|
|| is_os_connection_error(&lower)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1321,6 +1322,7 @@ mod tests {
|
|||||||
assert!(is_connection_error("Connection timed out"));
|
assert!(is_connection_error("Connection timed out"));
|
||||||
assert!(is_connection_error("socket closed"));
|
assert!(is_connection_error("socket closed"));
|
||||||
assert!(is_connection_error("unexpected eof"));
|
assert!(is_connection_error("unexpected eof"));
|
||||||
|
assert!(is_connection_error("Error occurred while creating a new object: error communicating with the server"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in new issue
Block a user