rewrite future select in upgrade_to_backup_protocol using select macro
and handle all ok/err cases with at least logging Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
66b4593b04
commit
6650a242fb
@ -106,13 +106,12 @@ fn upgrade_to_backup_protocol(
|
|||||||
let abort_future = worker.abort_future();
|
let abort_future = worker.abort_future();
|
||||||
|
|
||||||
let env2 = env.clone();
|
let env2 = env.clone();
|
||||||
let env3 = env.clone();
|
|
||||||
|
|
||||||
let req_fut = req_body
|
let mut req_fut = req_body
|
||||||
.on_upgrade()
|
.on_upgrade()
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.and_then(move |conn| {
|
.and_then(move |conn| {
|
||||||
env3.debug("protocol upgrade done");
|
env2.debug("protocol upgrade done");
|
||||||
|
|
||||||
let mut http = hyper::server::conn::Http::new();
|
let mut http = hyper::server::conn::Http::new();
|
||||||
http.http2_only(true);
|
http.http2_only(true);
|
||||||
@ -124,36 +123,39 @@ fn upgrade_to_backup_protocol(
|
|||||||
http.serve_connection(conn, service)
|
http.serve_connection(conn, service)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
});
|
});
|
||||||
let abort_future = abort_future
|
let mut abort_future = abort_future
|
||||||
.map(|_| Err(format_err!("task aborted")));
|
.map(|_| Err(format_err!("task aborted")));
|
||||||
|
|
||||||
use futures::future::Either;
|
async move {
|
||||||
future::select(req_fut, abort_future)
|
let res = select!{
|
||||||
.map(|res| match res {
|
req = req_fut => req,
|
||||||
Either::Left((Ok(res), _)) => Ok(res),
|
abrt = abort_future => abrt,
|
||||||
Either::Left((Err(err), _)) => Err(err),
|
};
|
||||||
Either::Right((Ok(res), _)) => Ok(res),
|
|
||||||
Either::Right((Err(err), _)) => Err(err),
|
match (res, env.ensure_finished()) {
|
||||||
})
|
(Ok(_), Ok(())) => {
|
||||||
.and_then(move |_result| async move {
|
|
||||||
env.ensure_finished()?;
|
|
||||||
env.log("backup finished sucessfully");
|
env.log("backup finished sucessfully");
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
},
|
||||||
.then(move |result| async move {
|
(Err(err), Ok(())) => {
|
||||||
if let Err(err) = result {
|
// ignore errors after finish
|
||||||
match env2.ensure_finished() {
|
env.log(format!("backup had errors but finished: {}", err));
|
||||||
Ok(()) => {}, // ignore error after finish
|
|
||||||
_ => {
|
|
||||||
env2.log(format!("backup failed: {}", err));
|
|
||||||
env2.log("removing failed backup");
|
|
||||||
env2.remove_backup()?;
|
|
||||||
return Err(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
},
|
||||||
|
(Ok(_), Err(err)) => {
|
||||||
|
env.log(format!("backup ended and finish failed: {}", err));
|
||||||
|
env.log("removing unfinished backup");
|
||||||
|
env.remove_backup()?;
|
||||||
|
Err(err)
|
||||||
|
},
|
||||||
|
(Err(err), Err(_)) => {
|
||||||
|
env.log(format!("backup failed: {}", err));
|
||||||
|
env.log("removing failed backup");
|
||||||
|
env.remove_backup()?;
|
||||||
|
Err(err)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let response = Response::builder()
|
let response = Response::builder()
|
||||||
|
Loading…
Reference in New Issue
Block a user