From 803d96bf8c85cd35191cf9cc2cb2288f41c066b6 Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 25 Mar 2026 08:05:45 -0400 Subject: [PATCH] feat(subsonic): handle ErrTranscodingBusy in GetTranscodeStream with HTTP 503 --- server/subsonic/transcode.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/subsonic/transcode.go b/server/subsonic/transcode.go index 4e494b324..eb50fc251 100644 --- a/server/subsonic/transcode.go +++ b/server/subsonic/transcode.go @@ -379,8 +379,13 @@ func (api *Router) GetTranscodeStream(w http.ResponseWriter, r *http.Request) (* } // Create stream - stream, err := api.streamer.NewStream(ctx, mf, streamReq) + s, err := api.streamer.NewStream(ctx, mf, streamReq) if err != nil { + if errors.Is(err, stream.ErrTranscodingBusy) { + log.Warn(ctx, "Transcoding throttle full", "mediaID", mediaID) + http.Error(w, "Service Unavailable", http.StatusServiceUnavailable) + return nil, nil + } log.Error(ctx, "Error creating stream", "mediaID", mediaID, err) http.Error(w, "Internal Server Error", http.StatusInternalServerError) return nil, nil @@ -388,14 +393,14 @@ func (api *Router) GetTranscodeStream(w http.ResponseWriter, r *http.Request) (* // Make sure the stream will be closed at the end defer func() { - if err := stream.Close(); err != nil && log.IsGreaterOrEqualTo(log.LevelDebug) { - log.Error("Error closing stream", "id", mediaID, "file", stream.Name(), err) + if err := s.Close(); err != nil && log.IsGreaterOrEqualTo(log.LevelDebug) { + log.Error("Error closing stream", "id", mediaID, "file", s.Name(), err) } }() w.Header().Set("X-Content-Type-Options", "nosniff") - n, err := stream.Serve(ctx, w, r) + n, err := s.Serve(ctx, w, r) if err != nil || n == 0 { http.Error(w, "Internal Server Error", http.StatusInternalServerError) }