You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Overhaul stats: Implement a graceful shutdown for broadcast channels #1405
In this issue I changed the events channels from mpsc to broadcast. I wanted to have many listeners. It's working fine. However when you send the halt signal to the applcaition (CRTL+c) you get this erros in the logs:
The problem is we drop the sender and the listener return an error because the channel is closed. We should implement a gracefully shutdown notifying listeners and giving them time to finish processing the current events.
Since I don't see an option in the broadcast channel to notify listener we need to research other alternatives.
changed the title [-]Overhaul stats: implement a graceful shutdown for broadcast channels[/-][+]Overhaul stats: Implement a graceful shutdown for broadcast channels[/+]on Apr 11, 2025
Activity
josecelano commentedon Mar 21, 2025
First ideas using AI.
cc @da2ce7
In Tokio, you can gracefully close a broadcast channel by using a combination of techniques. Here are a few approaches:
This example provides:
NotifyThe shutdown process:
This approach ensures:
You can extend this pattern by:
[-]Overhaul stats: implement a graceful shutdown for broadcast channels[/-][+]Overhaul stats: Implement a graceful shutdown for broadcast channels[/+]josecelano commentedon Apr 23, 2025
Depends on: #1449
josecelano commentedon Apr 25, 2025
In the first iteration, we can just listen for the halt signal (CTRL+c) in the job. See #1477
josecelano commentedon Apr 25, 2025
That would be incompatible with this issue. I mean, once we send a message to shutdown the listeners, they cannot listen for the CTRL+c signal.
fix: [torrust#1477] shutdown event listeners on CRTL+c signal
fix: [torrust#1477] shutdown event listeners on CRTL+c signal
Merge #1487: Fix shutdown message and improve it
josecelano commentedon Jun 10, 2025
Consider also https://tokio.rs/tokio/topics/shutdown
cc @da2ce7
refactor: [torrust#1405] gracefull shutdown for listeners
Merge #1587: Graceful shutdown for event listeners
josecelano commentedon Jun 19, 2025
Relates to: #1588