mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-10 23:12:54 +00:00
## Problem When a connection terminates its maintain_cancel_key task keeps running until the CANCEL_KEY_REFRESH sleep finishes and then it triggers another cancel key TTL refresh before exiting. ## Summary of changes * Check for cancellation while sleeping and interrupt sleep. * If cancelled, break the loop, don't send a refresh cmd.
23 lines
613 B
Rust
23 lines
613 B
Rust
use std::pin::pin;
|
|
|
|
use futures::future::{Either, select};
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
pub async fn run_until_cancelled<F: Future>(
|
|
f: F,
|
|
cancellation_token: &CancellationToken,
|
|
) -> Option<F::Output> {
|
|
run_until(f, cancellation_token.cancelled()).await.ok()
|
|
}
|
|
|
|
/// Runs the future `f` unless interrupted by future `condition`.
|
|
pub async fn run_until<F1: Future, F2: Future>(
|
|
f: F1,
|
|
condition: F2,
|
|
) -> Result<F1::Output, F2::Output> {
|
|
match select(pin!(f), pin!(condition)).await {
|
|
Either::Left((f1, _)) => Ok(f1),
|
|
Either::Right((f2, _)) => Err(f2),
|
|
}
|
|
}
|