Skip to content

Fix shutdown message and improve it - #1487

Merged
josecelano merged 8 commits into
torrust:developfrom
josecelano:1477-fix-shutdown-message-and-improve-it
Apr 29, 2025
Merged

josecelano merged 8 commits into
torrust:developfrom
josecelano:1477-fix-shutdown-message-and-improve-it

Conversation

@josecelano

@josecelano josecelano commented Apr 29, 2025 •

Copy link
Copy Markdown
Member

Fix shutdown message and improve it for HTTP servers (they all use Axum).

Subtasks

  • Hard timeout for shutdown. Stop the loop even when there are alive connections after the grace period.
  • Show socket-bound address in logs.
  • Fix bug, not showing the message passed as a parameter.
  • Event listeners should listen to CRTL+c signal. Temporary solution until we implement:
  • Add a job manager to give a name to all jobs and identify them when the app shuts down.

Graceful shutdown now enforces a hard timeout 5 seconds after the grace period.
Prevents indefinite waits when connections remain open too long.
@josecelano josecelano added Enhancement / Feature Request Something New Code Cleanup / Refactoring Tidying and Making Neat - Admin - Enjoyable to Install and Setup our Software labels Apr 29, 2025
@josecelano
josecelano requested a review from da2ce7 April 29, 2025 11:54
@josecelano josecelano self-assigned this Apr 29, 2025
@codecov

codecov Bot commented Apr 29, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 70.39106% with 53 lines in your changes missing coverage. Please review.

Project coverage is 84.29%. Comparing base (ef6c91d) to head (8f42271).
Report is 9 commits behind head on develop.

Files with missing lines Patch % Lines
src/app.rs 66.07% 15 Missing and 4 partials ⚠️
...dp-tracker-server/src/statistics/event/listener.rs 43.75% 9 Missing ⚠️
.../udp-tracker-core/src/statistics/event/listener.rs 46.66% 8 Missing ⚠️
...http-tracker-core/src/statistics/event/listener.rs 68.75% 4 Missing and 1 partial ⚠️
src/bootstrap/jobs/manager.rs 90.69% 1 Missing and 3 partials ⚠️
src/bootstrap/jobs/http_tracker_core.rs 81.81% 2 Missing ⚠️
src/bootstrap/jobs/udp_tracker_core.rs 80.00% 2 Missing ⚠️
src/bootstrap/jobs/udp_tracker_server.rs 80.00% 2 Missing ⚠️
src/console/profiling.rs 0.00% 1 Missing ⚠️
src/main.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1487      +/-   ##
===========================================
- Coverage    84.33%   84.29%   -0.04%     
===========================================
  Files          251      255       +4     
  Lines        19821    19878      +57     
  Branches     19821    19878      +57     
===========================================
+ Hits         16716    16757      +41     
- Misses        2798     2806       +8     
- Partials       307      315       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…vent listeners

The "jobs" folder should contain all the jogs run by the main app.
This fixes the problem of adding the jobs for event listeners in the
main app JoinHandle vector. It was not possible to add the handles for
those tokio tasks becuase in the main app we wait for all jobs and those
jobs never end.

```rust
async fn main() {
    let (_app_container, jobs) = app::run().await;

    // handle the signals
    tokio::select! {
        _ = tokio::signal::ctrl_c() => {
            tracing::info!("Torrust tracker shutting down ...");

            // Await for all jobs to shutdown
            futures::future::join_all(jobs).await;

            tracing::info!("Torrust tracker successfully shutdown.");
        }
    }
}
```

Now, we can wait for them becuase they listen for the halt signal.

We will implement the shutdown in a different way in a new PR. See

torrust#1405

Instead of listen to the CRTL+c signal the main app will send a "stop"
event to the listeners. The final goal it only the main app listen for
this external signal and it propagates the shutdown in cascade via
normal internal messages or channels.
@josecelano
josecelano force-pushed the 1477-fix-shutdown-message-and-improve-it branch from df5c2f6 to faf8111 Compare April 29, 2025 15:20
@josecelano

josecelano commented Apr 29, 2025 •

Copy link
Copy Markdown
Member Author

New messages during the shutdown:

image

It:

- Give a name to all jobs so they can be identify later in logs.
- Wait for all jobs to finish when the app receives teh halt signal
  (CRTL+c)
- Only waits for a grace period per job.
- Shows a message when a job don't complete in time.

This could be improved in the future:

- By showing a message every second while we are waiting for a job to finish.
- Waiting for all of them in paralell.
@josecelano
josecelano marked this pull request as ready for review April 29, 2025 16:46
@josecelano

Copy link
Copy Markdown
Member Author

ACK 8f42271

@josecelano
josecelano merged commit 659d174 into torrust:develop Apr 29, 2025
@da2ce7

da2ce7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Post-merge note: this pull request requested a review from this account and was closed without one at its final head. A post-merge review will not be done: Only 110 of the 285 executable lines it added remain on the default branch, at their own paths or in the files those paths were later renamed to; the rest has since been rewritten or removed.

This branch was previously deployed

1 inactive deployment
coverage — 8f42271e Deployed Apr 29, 2025 by josecelano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

- Admin - Enjoyable to Install and Setup our Software Code Cleanup / Refactoring Tidying and Making Neat Enhancement / Feature Request Something New

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants