mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-13 21:27:25 +08:00
fix wireguard not respond after idle for 120s
This commit is contained in:
@@ -499,17 +499,20 @@ pub async fn proxy_three_node_disconnect_test(#[values("tcp", "wg")] proto: &str
|
|||||||
|
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
for _ in 1..=2 {
|
for _ in 1..=2 {
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(8)).await;
|
|
||||||
// inst4 should be in inst1's route list
|
// inst4 should be in inst1's route list
|
||||||
let routes = insts[0].get_peer_manager().list_routes().await;
|
wait_for_condition(
|
||||||
assert!(
|
|| async {
|
||||||
routes
|
insts[0]
|
||||||
.iter()
|
.get_peer_manager()
|
||||||
.find(|r| r.peer_id == inst4.peer_id())
|
.list_routes()
|
||||||
.is_some(),
|
.await
|
||||||
"inst4 should be in inst1's route list, {:?}",
|
.iter()
|
||||||
routes
|
.find(|r| r.peer_id == inst4.peer_id())
|
||||||
);
|
.is_some()
|
||||||
|
},
|
||||||
|
Duration::from_secs(8),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
set_link_status("net_d", false);
|
set_link_status("net_d", false);
|
||||||
let _t = ScopedTask::from(tokio::spawn(async move {
|
let _t = ScopedTask::from(tokio::spawn(async move {
|
||||||
@@ -520,14 +523,25 @@ pub async fn proxy_three_node_disconnect_test(#[values("tcp", "wg")] proto: &str
|
|||||||
}));
|
}));
|
||||||
wait_for_condition(
|
wait_for_condition(
|
||||||
|| async {
|
|| async {
|
||||||
insts[2]
|
let ret = insts[2]
|
||||||
.get_peer_manager()
|
.get_peer_manager()
|
||||||
.get_peer_map()
|
.get_peer_map()
|
||||||
.list_peers_with_conn()
|
.list_peers_with_conn()
|
||||||
.await
|
.await
|
||||||
.iter()
|
.iter()
|
||||||
.find(|r| **r == inst4.peer_id())
|
.find(|r| **r == inst4.peer_id())
|
||||||
.is_none()
|
.is_none();
|
||||||
|
if !ret {
|
||||||
|
println!(
|
||||||
|
"conn info: {:?}",
|
||||||
|
insts[2]
|
||||||
|
.get_peer_manager()
|
||||||
|
.get_peer_map()
|
||||||
|
.list_peer_conns(inst4.peer_id())
|
||||||
|
.await
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ret
|
||||||
},
|
},
|
||||||
// 0 down, assume last packet is recv in -0.01
|
// 0 down, assume last packet is recv in -0.01
|
||||||
// [2, 7) send ping
|
// [2, 7) send ping
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
net::{Ipv4Addr, SocketAddr},
|
net::{Ipv4Addr, SocketAddr},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Duration,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
@@ -10,7 +9,7 @@ use cidr::Ipv4Inet;
|
|||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use pnet::packet::ipv4::Ipv4Packet;
|
use pnet::packet::ipv4::Ipv4Packet;
|
||||||
use tokio::{task::JoinSet, time::timeout};
|
use tokio::task::JoinSet;
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -96,20 +95,16 @@ impl WireGuardImpl {
|
|||||||
let mut map_key = None;
|
let mut map_key = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let msg = match timeout(Duration::from_secs(120), stream.next()).await {
|
let msg = match stream.next().await {
|
||||||
Ok(Some(Ok(msg))) => msg,
|
Some(Ok(msg)) => msg,
|
||||||
Ok(Some(Err(err))) => {
|
Some(Err(err)) => {
|
||||||
tracing::error!(?err, "Failed to receive from wg client");
|
tracing::error!(?err, "Failed to receive from wg client");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
None => {
|
||||||
tracing::info!("Wireguard client disconnected");
|
tracing::info!("Wireguard client disconnected");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
|
||||||
tracing::error!(?err, "Timeout while receiving from wg client");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(msg.packet_type(), ZCPacketType::WG);
|
assert_eq!(msg.packet_type(), ZCPacketType::WG);
|
||||||
|
|||||||
Reference in New Issue
Block a user