mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
refactor(tunnel): 移除 proxy 连接 idle timeout 机制
idle timeout 在实际使用中容易误断活跃连接,移除该逻辑并简化 reader 循环。
This commit is contained in:
@@ -27,7 +27,6 @@ pub enum SendStatus {
|
|||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct ConnConfig {
|
pub struct ConnConfig {
|
||||||
pub ping_interval: Duration,
|
pub ping_interval: Duration,
|
||||||
pub idle_timeout: Duration,
|
|
||||||
pub outbound_queue_capacity: usize,
|
pub outbound_queue_capacity: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -490,7 +490,6 @@ mod tests {
|
|||||||
ControlPlaneClient::disabled(),
|
ControlPlaneClient::disabled(),
|
||||||
ConnConfig {
|
ConnConfig {
|
||||||
ping_interval: Duration::from_secs(15),
|
ping_interval: Duration::from_secs(15),
|
||||||
idle_timeout: Duration::from_secs(0),
|
|
||||||
outbound_queue_capacity: 128,
|
outbound_queue_capacity: 128,
|
||||||
},
|
},
|
||||||
128,
|
128,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
/// Handles the lifecycle of a single aether-proxy connection:
|
/// Handles the lifecycle of a single aether-proxy connection:
|
||||||
/// accept -> authenticate (headers) -> read loop -> cleanup
|
/// accept -> authenticate (headers) -> read loop -> cleanup
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use aether_runtime::bounded_queue;
|
use aether_runtime::bounded_queue;
|
||||||
use axum::extract::ws::{Message, WebSocket};
|
use axum::extract::ws::{Message, WebSocket};
|
||||||
@@ -81,7 +80,7 @@ pub async fn handle_proxy_connection(
|
|||||||
let reader_hub = hub.clone();
|
let reader_hub = hub.clone();
|
||||||
let reader_conn = conn.clone();
|
let reader_conn = conn.clone();
|
||||||
let reader = tokio::spawn(async move {
|
let reader = tokio::spawn(async move {
|
||||||
run_proxy_reader(ws_rx, reader_hub, reader_conn, cfg.idle_timeout).await;
|
run_proxy_reader(ws_rx, reader_hub, reader_conn).await;
|
||||||
});
|
});
|
||||||
|
|
||||||
let _ = reader.await;
|
let _ = reader.await;
|
||||||
@@ -89,7 +88,7 @@ pub async fn handle_proxy_connection(
|
|||||||
conn.request_close();
|
conn.request_close();
|
||||||
hub.unregister_proxy(conn_id, &node_id);
|
hub.unregister_proxy(conn_id, &node_id);
|
||||||
drop(conn);
|
drop(conn);
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||||
writer.abort();
|
writer.abort();
|
||||||
let _ = writer.await;
|
let _ = writer.await;
|
||||||
}
|
}
|
||||||
@@ -98,24 +97,10 @@ async fn run_proxy_reader(
|
|||||||
mut ws_rx: futures_util::stream::SplitStream<WebSocket>,
|
mut ws_rx: futures_util::stream::SplitStream<WebSocket>,
|
||||||
hub: Arc<HubRouter>,
|
hub: Arc<HubRouter>,
|
||||||
conn: Arc<ProxyConn>,
|
conn: Arc<ProxyConn>,
|
||||||
idle_timeout: Duration,
|
|
||||||
) {
|
) {
|
||||||
let idle_enabled = !idle_timeout.is_zero();
|
|
||||||
let mut oversized_count = 0u32;
|
let mut oversized_count = 0u32;
|
||||||
loop {
|
loop {
|
||||||
let msg = if idle_enabled {
|
let msg = ws_rx.next().await;
|
||||||
tokio::select! {
|
|
||||||
msg = ws_rx.next() => msg,
|
|
||||||
_ = tokio::time::sleep(idle_timeout) => {
|
|
||||||
warn!(conn_id = conn.id, node_id = %conn.node_id, "proxy idle timeout");
|
|
||||||
let _ = conn.send(Message::Binary(protocol::encode_goaway().into()));
|
|
||||||
conn.request_close();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ws_rx.next().await
|
|
||||||
};
|
|
||||||
|
|
||||||
match msg {
|
match msg {
|
||||||
Some(Ok(Message::Binary(data))) => {
|
Some(Ok(Message::Binary(data))) => {
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ pub(crate) const TUNNEL_NODE_STATUS_PATH: &str = "/api/internal/tunnel/node-stat
|
|||||||
pub(crate) const TUNNEL_RELAY_PATH_PATTERN: &str = "/api/internal/tunnel/relay/{node_id}";
|
pub(crate) const TUNNEL_RELAY_PATH_PATTERN: &str = "/api/internal/tunnel/relay/{node_id}";
|
||||||
pub(crate) const TUNNEL_ROUTE_FAMILY: &str = "tunnel_manage";
|
pub(crate) const TUNNEL_ROUTE_FAMILY: &str = "tunnel_manage";
|
||||||
|
|
||||||
const DEFAULT_PROXY_IDLE_TIMEOUT_MS: u64 = 2_000;
|
|
||||||
const DEFAULT_PING_INTERVAL_MS: u64 = 500;
|
const DEFAULT_PING_INTERVAL_MS: u64 = 500;
|
||||||
const DEFAULT_MAX_STREAMS: usize = 2048;
|
const DEFAULT_MAX_STREAMS: usize = 2048;
|
||||||
const DEFAULT_OUTBOUND_QUEUE_CAPACITY: usize = 128;
|
const DEFAULT_OUTBOUND_QUEUE_CAPACITY: usize = 128;
|
||||||
@@ -417,7 +416,6 @@ impl EmbeddedTunnelState {
|
|||||||
build_embedded_control_plane(Arc::clone(&data), attachment_directory.clone()),
|
build_embedded_control_plane(Arc::clone(&data), attachment_directory.clone()),
|
||||||
ConnConfig {
|
ConnConfig {
|
||||||
ping_interval: Duration::from_millis(DEFAULT_PING_INTERVAL_MS),
|
ping_interval: Duration::from_millis(DEFAULT_PING_INTERVAL_MS),
|
||||||
idle_timeout: Duration::from_millis(DEFAULT_PROXY_IDLE_TIMEOUT_MS),
|
|
||||||
outbound_queue_capacity: DEFAULT_OUTBOUND_QUEUE_CAPACITY,
|
outbound_queue_capacity: DEFAULT_OUTBOUND_QUEUE_CAPACITY,
|
||||||
},
|
},
|
||||||
DEFAULT_MAX_STREAMS,
|
DEFAULT_MAX_STREAMS,
|
||||||
@@ -566,7 +564,6 @@ impl Default for EmbeddedTunnelState {
|
|||||||
impl fmt::Debug for EmbeddedTunnelState {
|
impl fmt::Debug for EmbeddedTunnelState {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("EmbeddedTunnelState")
|
f.debug_struct("EmbeddedTunnelState")
|
||||||
.field("proxy_idle_timeout_ms", &DEFAULT_PROXY_IDLE_TIMEOUT_MS)
|
|
||||||
.field("ping_interval_ms", &DEFAULT_PING_INTERVAL_MS)
|
.field("ping_interval_ms", &DEFAULT_PING_INTERVAL_MS)
|
||||||
.field("max_streams", &DEFAULT_MAX_STREAMS)
|
.field("max_streams", &DEFAULT_MAX_STREAMS)
|
||||||
.field("outbound_queue_capacity", &DEFAULT_OUTBOUND_QUEUE_CAPACITY)
|
.field("outbound_queue_capacity", &DEFAULT_OUTBOUND_QUEUE_CAPACITY)
|
||||||
|
|||||||
Reference in New Issue
Block a user