Fix stream header invalidation and source task cleanup

Invalidate the cached OGG header immediately when restarting the FLAC encoder to prevent clients from receiving stale data.

Also improve the player source cleanup by draining the chunk receiver and adding a timeout when waiting for the emit task to finish, preventing potential hangs when the downstream pipeline is saturated.
This commit is contained in:
2026-03-02 20:02:25 +01:00
parent 2b0def806a
commit d1be71ff47
2 changed files with 16 additions and 2 deletions

View File

@@ -490,6 +490,11 @@ impl SharedSinkContext {
debug!("Restarting FLAC encoder for new track");
// Invalider le header en cache immédiatement : tout nouveau client qui se connecte
// pendant le restart attendra (Poll::Pending) jusqu'à ce que le nouveau header OGG
// soit prêt, évitant qu'il reçoive l'ancien header suivi des nouvelles données.
*self.header.write().await = None;
let last_timestamp = *self.current_timestamp.read().await;
debug!("Last timestamp before restart: {:.3}s", last_timestamp);

View File

@@ -469,8 +469,17 @@ impl PlayerSourceLogic {
}
}
// Attendre que la tâche source se termine proprement
let _ = emit_task.await;
// Vider chunk_rx pour débloquer emit_task si elle est bloquée sur un send
// (peut arriver si le pipeline en aval est saturé au moment du cancel)
while chunk_rx.try_recv().is_ok() {}
// Attendre que la tâche source se termine, avec timeout de sécurité
tokio::select! {
_ = emit_task => {}
_ = tokio::time::sleep(std::time::Duration::from_millis(500)) => {
warn!("PlayerSource: emit_task did not finish in time after cancel");
}
}
result
}
}