Skip to content

Commit

Permalink
Fix deadlock during codec error
Browse files Browse the repository at this point in the history
Fix a deadlock causing the bot to freeze when an unsupported audio
codec was used.
  • Loading branch information
AlexGustafsson committed Oct 19, 2024
1 parent 6a9373e commit 1a99251
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ func (b *Bot) Play(opus chan<- []byte, songs chan<- string) error {
failures = 0
} else if errors.Is(err, ErrUnsupportedAudioCodec) {
slog.Error("Failed to play unsupported entry", slog.String("title", entry.Title))
// Skip to next
// TODO: Communicate the failure - write in chat (currently no way to send
// messages from the bot) or get the URL immediately on queue and complain
// then?
} else {
slog.Error("Failed to play entry", slog.Any("error", err))
// Try next
Expand Down Expand Up @@ -411,6 +415,7 @@ func (b *Bot) playOnce(entry state.PlaylistEntry, opus chan<- []byte) error {
if !strings.EqualFold(stream.MimeType(), `audio/webm; codecs="opus"`) {
// For now, don't support other formats as they would need to be processed
// by ffmpeg
b.mutex.Unlock()
return fmt.Errorf("%w: %s", ErrUnsupportedAudioCodec, stream.MimeType())
}

Expand Down

0 comments on commit 1a99251

Please sign in to comment.