WS-I: review fixes (connection cap, header timeout, SIGHUP on plain path, HTTP/1.1 only)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5972b762f
commit
9f2bbc7d14
6 files changed
+252
-18
No files matched your search
+27
-3
@@ -105,6 +105,10 @@ const DRAIN_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
|
||||
const EXPORTER_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
|
||||
|
||||
async fn serve(config: Config) -> Result<()> {
|
||||
// Install SIGHUP handling before anything else: the default action would
|
||||
// terminate the process, with or without TLS.
|
||||
let hup = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::hangup())
|
||||
.context("installing SIGHUP handler")?;
|
||||
let guard = telemetry::init(&config).context("initialising telemetry")?;
|
||||
let db = if config.auth.enabled {
|
||||
Some(db::open(&config).await?)
|
||||
@@ -136,8 +140,22 @@ async fn serve(config: Config) -> Result<()> {
|
||||
let exporters = telemetry::spawn_exporters(state.clone());
|
||||
let pool = state.db.clone();
|
||||
let app = server::build_router(state);
|
||||
if let Some((_, cert)) = &tls {
|
||||
tls::spawn_sighup_reload(cert.clone(), shutdown.clone());
|
||||
match &tls {
|
||||
Some((_, cert)) => tls::spawn_sighup_reload(cert.clone(), hup, shutdown.clone()),
|
||||
None => {
|
||||
// Plain path: SIGHUP is ignored (logged only), nothing to reload.
|
||||
let stop = shutdown.clone();
|
||||
let mut hup = hup;
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = stop.cancelled() => break,
|
||||
r = hup.recv() => if r.is_none() { break },
|
||||
}
|
||||
tracing::info!("SIGHUP received; nothing to reload (TLS is disabled)");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let signal_token = shutdown.clone();
|
||||
@@ -152,7 +170,13 @@ async fn serve(config: Config) -> Result<()> {
|
||||
// immediately. Bound the drain so a stuck client cannot hang SIGTERM.
|
||||
let serving: std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>> + Send>> = match tls
|
||||
{
|
||||
Some((acceptor, _)) => Box::pin(tls::serve_tls(listener, acceptor, app, shutdown.clone())),
|
||||
Some((acceptor, _)) => Box::pin(tls::serve_tls(
|
||||
listener,
|
||||
acceptor,
|
||||
app,
|
||||
shutdown.clone(),
|
||||
tls::Limits::default(),
|
||||
)),
|
||||
None => Box::pin(server::serve_listener(listener, app, shutdown.clone())),
|
||||
};
|
||||
tokio::pin!(serving);
|
||||
|
||||
Reference in new issue
Block a user