mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-15 22:27:26 +08:00
fix high cpu usage when client proto mismatch (#481)
before this patch, invalid packat received by tunnel reader may cause a dead loop in handshake.
This commit is contained in:
@@ -133,15 +133,23 @@ impl PeerConn {
|
||||
|
||||
let mut locked = self.recv.lock().await;
|
||||
let recv = locked.as_mut().unwrap();
|
||||
let Some(rsp) = recv.next().await else {
|
||||
return Err(Error::WaitRespError(
|
||||
"conn closed during wait handshake response".to_owned(),
|
||||
));
|
||||
let rsp = match recv.next().await {
|
||||
Some(Ok(rsp)) => rsp,
|
||||
Some(Err(e)) => {
|
||||
return Err(Error::WaitRespError(format!(
|
||||
"conn recv error during wait handshake response, err: {:?}",
|
||||
e
|
||||
)))
|
||||
}
|
||||
None => {
|
||||
return Err(Error::WaitRespError(
|
||||
"conn closed during wait handshake response".to_owned(),
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
*need_retry = true;
|
||||
|
||||
let rsp = rsp?;
|
||||
let Some(peer_mgr_hdr) = rsp.peer_manager_header() else {
|
||||
return Err(Error::WaitRespError(format!(
|
||||
"unexpected packet: {:?}, cannot decode peer manager hdr",
|
||||
@@ -214,6 +222,9 @@ impl PeerConn {
|
||||
Error::WaitRespError("send handshake request error".to_owned())
|
||||
})?;
|
||||
|
||||
// yield to send the response packet
|
||||
tokio::task::yield_now().await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user