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:
Sijie.Sun
2024-11-19 21:36:09 +08:00
committed by GitHub
parent 1324e6163e
commit 3f47f37470
2 changed files with 28 additions and 13 deletions

View File

@@ -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(())
}