LCOV - code coverage report
Current view: top level - proxy/src - lib.rs (source / functions) Coverage Total Hit
Test: 8ac049b474321fdc72ddcb56d7165153a1a900e8.info Lines: 95.7 % 23 22
Test Date: 2023-09-06 10:18:01 Functions: 50.0 % 12 6

            Line data    Source code
       1              : use std::convert::Infallible;
       2              : 
       3              : use anyhow::{bail, Context};
       4              : use tokio::task::JoinError;
       5              : use tokio_util::sync::CancellationToken;
       6              : use tracing::warn;
       7              : 
       8              : pub mod auth;
       9              : pub mod cache;
      10              : pub mod cancellation;
      11              : pub mod compute;
      12              : pub mod config;
      13              : pub mod console;
      14              : pub mod error;
      15              : pub mod http;
      16              : pub mod logging;
      17              : pub mod metrics;
      18              : pub mod parse;
      19              : pub mod protocol2;
      20              : pub mod proxy;
      21              : pub mod sasl;
      22              : pub mod scram;
      23              : pub mod stream;
      24              : pub mod url;
      25              : pub mod waiters;
      26              : 
      27              : /// Handle unix signals appropriately.
      28           15 : pub async fn handle_signals(token: CancellationToken) -> anyhow::Result<Infallible> {
      29              :     use tokio::signal::unix::{signal, SignalKind};
      30              : 
      31           15 :     let mut hangup = signal(SignalKind::hangup())?;
      32           15 :     let mut interrupt = signal(SignalKind::interrupt())?;
      33           15 :     let mut terminate = signal(SignalKind::terminate())?;
      34              : 
      35              :     loop {
      36           30 :         tokio::select! {
      37           45 :             // Hangup is commonly used for config reload.
      38           45 :             _ = hangup.recv() => {
      39           45 :                 warn!("received SIGHUP; config reload is not supported");
      40           45 :             }
      41           45 :             // Shut down the whole application.
      42           45 :             _ = interrupt.recv() => {
      43           45 :                 warn!("received SIGINT, exiting immediately");
      44           45 :                 bail!("interrupted");
      45           45 :             }
      46           45 :             _ = terminate.recv() => {
      47           45 :                 warn!("received SIGTERM, shutting down once all existing connections have closed");
      48           45 :                 token.cancel();
      49           45 :             }
      50           45 :         }
      51              :     }
      52            0 : }
      53              : 
      54              : /// Flattens `Result<Result<T>>` into `Result<T>`.
      55           29 : pub fn flatten_err<T>(r: Result<anyhow::Result<T>, JoinError>) -> anyhow::Result<T> {
      56           29 :     r.context("join error").and_then(|x| x)
      57           29 : }
        

Generated by: LCOV version 2.1-beta