Skip to content

Commit 039b933

Browse files
committed
fix(stats): skip silence penalty for transcoded outputs
Transcoded mounts gate their encoder on listener count (transcode.go EncodeMP3 / EncodeOpus return early when ListenersCount()==0), so LastDataReceived doesn't tick while the mount is idle. The 2%/s silence penalty (kicking in after 5s) then accumulates against a perfectly healthy mount nobody happens to be listening to, surfacing as 50-60% health in the dashboard for an idle /electronica-mp3-128. Skip the silence-penalty branch for streams flagged IsTranscoded. The upstream source mount still has its own silence-penalty health, which reflects real-source stalls. Loss-ratio (BytesIn / (BytesIn + BytesDropped)) still applies to transcoded outputs so a slow listener that wraps the buffer is still visible.
1 parent b8c7371 commit 039b933

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

relay/stats.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,25 @@ func (s *Stream) Snapshot() StreamStats {
4646
health = (float64(bi) / float64(total)) * 100.0
4747
}
4848

49-
// 2. Source Stall Penalty (User Request)
50-
// If we haven't received data for more than 5 seconds, health starts dropping
51-
if !s.LastDataReceived.IsZero() {
52-
silence := time.Since(s.LastDataReceived)
53-
if silence > 5*time.Second {
54-
penalty := float64(silence/time.Second) * 2.0 // 2% per second of silence
55-
health -= penalty
49+
// 2. Source Stall Penalty.
50+
// Skipped for transcoded outputs: their encoder is gated on
51+
// listener count (transcode.go EncodeMP3/EncodeOpus return early
52+
// when ListenersCount()==0) so LastDataReceived doesn't tick
53+
// while the mount is idle. Applying the silence penalty there
54+
// would surface as 50-60% health on perfectly healthy mounts
55+
// nobody happens to be listening to. The upstream source mount
56+
// has its own health metric that reflects real-source stalls.
57+
if !s.IsTranscoded {
58+
if !s.LastDataReceived.IsZero() {
59+
silence := time.Since(s.LastDataReceived)
60+
if silence > 5*time.Second {
61+
penalty := float64(silence/time.Second) * 2.0 // 2% per second of silence
62+
health -= penalty
63+
}
64+
} else if time.Since(s.Started) > 10*time.Second {
65+
// Never received data and stream started > 10s ago
66+
health = 0
5667
}
57-
} else if time.Since(s.Started) > 10*time.Second {
58-
// Never received data and stream started > 10s ago
59-
health = 0
6068
}
6169

6270
if health < 0 {

0 commit comments

Comments
 (0)