Skip to content

Overhaul stats: Implement a graceful shutdown for broadcast channels #1405

@josecelano

Description

@josecelano

Depends on: #1449
Relates to: #1385

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:

2025-03-21T16:11:39.493220Z ERROR bittorrent_udp_tracker_core::statistics::event::listener: Error receiving udp tracker core event: Closed
2025-03-21T16:11:39.493352Z ERROR bittorrent_http_tracker_core::statistics::event::listener: Error receiving http tracker core event: Closed
2025-03-21T16:11:39.493361Z ERROR torrust_udp_tracker_server::statistics::event::listener: Error receiving udp tracker server event: Closed

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.

cc @da2ce7

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions