mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 19:50:37 +03:00
Close stream when downloading files, fix fd leak
This commit is contained in:
parent
05c6cdea1a
commit
b8c5e49dd3
@ -127,11 +127,17 @@ func (api *Router) Download(w http.ResponseWriter, r *http.Request) (*responses.
|
||||
switch v := entity.(type) {
|
||||
case *model.MediaFile:
|
||||
stream, err := api.streamer.NewStream(ctx, id, format, maxBitRate)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Make sure the stream will be closed at the end, to avoid leakage
|
||||
defer func() {
|
||||
if err := stream.Close(); err != nil && log.CurrentLevel() >= log.LevelDebug {
|
||||
log.Error("Error closing stream", "id", id, "file", stream.Name(), err)
|
||||
}
|
||||
}()
|
||||
|
||||
disposition := fmt.Sprintf("attachment; filename=\"%s\"", stream.Name())
|
||||
w.Header().Set("Content-Disposition", disposition)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user