mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-03-20 07:58:55 +00:00
vm-virtio: Retry connections to vhost-user backends
If the connection to the backend fails, sleep and retry up to a count. This failure could happen because the backend is not yet ready to handle the connection which is a common case when working with a spawned backend. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
b04eb4770b
commit
d054dddcb3
@ -85,13 +85,31 @@ impl Master {
|
|||||||
|
|
||||||
/// Create a new vhost-user master endpoint.
|
/// Create a new vhost-user master endpoint.
|
||||||
///
|
///
|
||||||
|
/// Will retry as the backend may not be ready to accept the connection.
|
||||||
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `path` - path of Unix domain socket listener to connect to
|
/// * `path` - path of Unix domain socket listener to connect to
|
||||||
pub fn connect(path: &str, max_queue_num: u64) -> Result<Self> {
|
pub fn connect(path: &str, max_queue_num: u64) -> Result<Self> {
|
||||||
Ok(Self::new(
|
let mut retry_count = 5;
|
||||||
Endpoint::<MasterReq>::connect(path)?,
|
let endpoint = loop {
|
||||||
max_queue_num,
|
match Endpoint::<MasterReq>::connect(path) {
|
||||||
))
|
Ok(endpoint) => break Ok(endpoint),
|
||||||
|
Err(e) => match &e {
|
||||||
|
VhostUserError::SocketConnect(why) => {
|
||||||
|
if why.kind() == std::io::ErrorKind::ConnectionRefused && retry_count > 0 {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
retry_count -= 1;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break Err(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => break Err(e),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}?;
|
||||||
|
|
||||||
|
Ok(Self::new(endpoint, max_queue_num))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user