proxy: refactor some error handling and shutdowns (#4684)

## Problem

It took me a while to understand the purpose of all the tasks spawned in
the main functions.

## Summary of changes

Utilising the type system and less macros, plus much more comments,
document the shutdown procedure of each task in detail
This commit is contained in:
Conrad Ludgate
2023-07-13 11:03:37 +01:00
committed by GitHub
parent 444d6e337f
commit 0626e0bfd3
7 changed files with 80 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
use anyhow::anyhow;
use anyhow::{anyhow, bail};
use hyper::{Body, Request, Response, StatusCode};
use std::net::TcpListener;
use std::{convert::Infallible, net::TcpListener};
use tracing::info;
use utils::http::{endpoint, error::ApiError, json::json_response, RouterBuilder, RouterService};
@@ -12,7 +12,7 @@ fn make_router() -> RouterBuilder<hyper::Body, ApiError> {
endpoint::make_router().get("/v1/status", status_handler)
}
pub async fn task_main(http_listener: TcpListener) -> anyhow::Result<()> {
pub async fn task_main(http_listener: TcpListener) -> anyhow::Result<Infallible> {
scopeguard::defer! {
info!("http has shut down");
}
@@ -23,5 +23,5 @@ pub async fn task_main(http_listener: TcpListener) -> anyhow::Result<()> {
.serve(service().map_err(|e| anyhow!(e))?)
.await?;
Ok(())
bail!("hyper server without shutdown handling cannot shutdown successfully");
}