From 699132d271edbc8b49fa96e78889087de65bac42 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 10 Nov 2026 12:52:20 +0000 Subject: [PATCH] feat(signals)!: remove legacy shutdown API and bump to 0.6.0 Removes Halted, shutdown_signal, shutdown_signal_with_message and global_shutdown_signal (deprecated since 0.5.0), drops the tokio signal feature and derive_more, adds the 0.6.0 changelog. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 21 ++++++++++ Cargo.lock | 83 +------------------------------------ Cargo.toml | 5 +-- src/signals.rs | 110 ++----------------------------------------------- 4 files changed, 27 insertions(+), 192 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb6d82e..2a538ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## 0.6.0 + +### Removed + +The legacy shutdown API in `torrust_server_lib::signals`, deprecated since `0.5.0`, is removed. +This is a breaking release. + +| Removed | Migrate to | +| ------------------------------- | -------------------------------------------------------------------------------------------------------------------- | +| `Halted` | Inject a `tokio_util::sync::CancellationToken`. | +| `shutdown_signal` | `cancellation_signal(token)`. | +| `shutdown_signal_with_message` | `cancellation_signal(token)` followed by your own log line. | +| `global_shutdown_signal` | The executable subscribes to SIGINT/SIGTERM and cancels the injected token. | + +`Started` and `cancellation_signal` are unchanged. + +The crate no longer enables the `tokio` `signal` feature and no longer depends on `derive_more`. + +For the migration steps, see the `0.5.0` section below: executables own SIGINT/SIGTERM and cancel an +injected `CancellationToken`. + ## 0.5.0 ### Deprecated diff --git a/Cargo.lock b/Cargo.lock index 9984f6f..aa32fca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,15 +112,6 @@ version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc14f565cf027a105f7a44ccf9e5b424348421a1d8952a8fc9d499d313107789" -[[package]] -name = "convert_case" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "crc32fast" version = "1.5.0" @@ -130,29 +121,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "derive_more" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" -dependencies = [ - "derive_more-impl", -] - -[[package]] -name = "derive_more-impl" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version", - "syn", - "unicode-xid", -] - [[package]] name = "displaydoc" version = "0.2.6" @@ -164,16 +132,6 @@ dependencies = [ "syn", ] -[[package]] -name = "errno" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" -dependencies = [ - "libc", - "windows-sys", -] - [[package]] name = "find-msvc-tools" version = "0.1.9" @@ -516,27 +474,12 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - [[package]] name = "rustversion" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "semver" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" - [[package]] name = "serde" version = "1.0.228" @@ -573,16 +516,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" -[[package]] -name = "signal-hook-registry" -version = "1.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" -dependencies = [ - "errno", - "libc", -] - [[package]] name = "simd-adler32" version = "0.3.9" @@ -678,7 +611,6 @@ dependencies = [ "libc", "mio", "pin-project-lite", - "signal-hook-registry", "socket2", "tokio-macros", "windows-sys", @@ -722,9 +654,8 @@ dependencies = [ [[package]] name = "torrust-server-lib" -version = "0.5.0" +version = "0.6.0" dependencies = [ - "derive_more", "tokio", "tokio-util", "torrust-net-primitives", @@ -803,18 +734,6 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" -[[package]] -name = "unicode-segmentation" -version = "1.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" - -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "url" version = "2.5.8" diff --git a/Cargo.toml b/Cargo.toml index 8f63ca0..756726b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,10 @@ publish = true readme = "README.md" repository = "https://github.com/torrust/torrust-server-lib" rust-version = "1.88" -version = "0.5.0" +version = "0.6.0" [dependencies] -derive_more = { version = "2", features = [ "as_ref", "constructor", "display", "from" ] } -tokio = { version = "1", features = [ "macros", "net", "rt-multi-thread", "signal", "sync" ] } +tokio = { version = "1", features = [ "macros", "net", "rt-multi-thread", "sync" ] } tokio-util = { version = "0.7", features = [ "rt" ] } torrust-net-primitives = "0.1.0" tower-http = { version = "0", features = [ "compression-full", "cors", "propagate-header", "request-id", "trace" ] } diff --git a/src/signals.rs b/src/signals.rs index 8051f38..88b8aaa 100644 --- a/src/signals.rs +++ b/src/signals.rs @@ -1,5 +1,4 @@ //! This module contains functions to handle signals. -use derive_more::Display; use tokio_util::sync::CancellationToken; use torrust_net_primitives::service_binding::ServiceBinding; use tracing::instrument; @@ -13,110 +12,20 @@ pub struct Started { pub address: std::net::SocketAddr, } -/// This is the message that the "launcher" spawned task receives from the main -/// application process to notify the service to shutdown. -/// -#[deprecated( - since = "0.5.0", - note = "inject a `tokio_util::sync::CancellationToken` instead of sending `Halted` over a oneshot channel; removal is planned for torrust-server-lib 0.6.0" -)] -#[derive(Copy, Clone, Debug, Display)] -pub enum Halted { - Normal, -} - /// Resolves when the injected cancellation token is cancelled. /// -/// Unlike [`global_shutdown_signal`], this function never subscribes to an -/// operating-system signal. The caller owns the cancellation lifecycle. +/// This function never subscribes to an operating-system signal. The caller +/// owns the cancellation lifecycle. #[instrument(skip(cancellation_token))] pub async fn cancellation_signal(cancellation_token: CancellationToken) { cancellation_token.cancelled().await; } -/// Resolves on `ctrl_c` or the `terminate` signal. -/// -/// # Panics -/// -/// Will panic if the `ctrl_c` or `terminate` signal resolves with an error. -#[deprecated( - since = "0.5.0", - note = "libraries must not subscribe to SIGINT/SIGTERM; the executable should subscribe and cancel a `CancellationToken` passed to `cancellation_signal`; removal is planned for torrust-server-lib 0.6.0" -)] -#[instrument(skip())] -pub async fn global_shutdown_signal() { - let ctrl_c = async { - tokio::signal::ctrl_c().await.expect("failed to install Ctrl+C handler"); - }; - - #[cfg(unix)] - let terminate = async { - tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()) - .expect("failed to install signal handler") - .recv() - .await; - }; - - #[cfg(not(unix))] - let terminate = std::future::pending::<()>(); - - tokio::select! { - () = ctrl_c => {tracing::warn!("caught interrupt signal (ctrl-c), halting...");}, - () = terminate => {tracing::warn!("caught interrupt signal (terminate), halting...");} - } -} - -/// Resolves when the `stop_receiver` or the `global_shutdown_signal()` resolves. -/// -/// # Panics -/// -/// Will panic if the `stop_receiver` resolves with an error. -#[deprecated( - since = "0.5.0", - note = "use `cancellation_signal` with an injected `CancellationToken`; removal is planned for torrust-server-lib 0.6.0" -)] -#[allow( - deprecated, - reason = "the legacy function is implemented with the other legacy symbols until they are removed" -)] -#[instrument(skip(rx_halt))] -pub async fn shutdown_signal(rx_halt: tokio::sync::oneshot::Receiver) { - let halt = async { - match rx_halt.await { - Ok(signal) => signal, - Err(err) => panic!("Failed to install stop signal: {err}"), - } - }; - - tokio::select! { - signal = halt => { tracing::debug!("Halt signal processed: {}", signal) }, - () = global_shutdown_signal() => { tracing::debug!("Global shutdown signal processed") } - } -} - -/// Same as `shutdown_signal()`, but shows a message when it resolves. -#[deprecated( - since = "0.5.0", - note = "use `cancellation_signal` with an injected `CancellationToken` and log the message yourself; removal is planned for torrust-server-lib 0.6.0" -)] -#[allow( - deprecated, - reason = "the legacy function is implemented with the other legacy symbols until they are removed" -)] -#[instrument(skip(rx_halt))] -pub async fn shutdown_signal_with_message(rx_halt: tokio::sync::oneshot::Receiver, message: String) { - shutdown_signal(rx_halt).await; - - tracing::info!("{message}"); -} - #[cfg(test)] mod tests { - use tokio::sync::oneshot; use tokio_util::sync::CancellationToken; - #[allow(deprecated, reason = "the test covers the deprecated legacy API until it is removed")] - use super::{Halted, cancellation_signal, shutdown_signal}; + use super::cancellation_signal; #[tokio::test] async fn cancellation_signal_should_resolve_when_the_token_is_cancelled() { @@ -131,17 +40,4 @@ mod tests { wait_task.await.expect("cancellation wait task should complete"); } - - #[allow(deprecated, reason = "the test covers the deprecated legacy API until it is removed")] - #[tokio::test] - async fn shutdown_signal_should_resolve_when_it_receives_a_legacy_halted_message() { - let (halt_sender, halt_receiver) = oneshot::channel(); - let wait_task = tokio::spawn(shutdown_signal(halt_receiver)); - - halt_sender - .send(Halted::Normal) - .expect("legacy halt receiver should still be waiting"); - - wait_task.await.expect("legacy shutdown wait task should complete"); - } }