Skip to content

🎧 Your Personal Streaming Service

Fix file descriptor leaking.

Deluan4a7e86e98946
diff --git a/core/artwork/artwork.go b/core/artwork/artwork.go
index 3ed48d023..5d0677f38 100644
--- a/core/artwork/artwork.go
+++ b/core/artwork/artwork.go
@@ -65,7 +65,7 @@ func (a *artwork) Get(ctx context.Context, artID model.ArtworkID, size int) (rea
r, err := a.cache.Get(ctx, artReader)
if err != nil {
- if !errors.Is(err, context.Canceled) {
+ if !errors.Is(err, context.Canceled) && !errors.Is(err, ErrUnavailable) {
log.Error(ctx, "Error accessing image cache", "id", artID, "size", size, err)
}
return nil, time.Time{}, err
diff --git a/utils/cache/file_caches.go b/utils/cache/file_caches.go
index bbb008fd6..2125ff82a 100644
--- a/utils/cache/file_caches.go
+++ b/utils/cache/file_caches.go
@@ -85,7 +85,11 @@ func (fc *fileCache) invalidate(ctx context.Context, key string) error {
if !fc.cache.Exists(key) {
return nil
}
- return fc.cache.Remove(key)
+ err := fc.cache.Remove(key)
+ if err != nil {
+ log.Warn(ctx, "Error removing key from cache", "cache", fc.name, "key", key, err)
+ }
+ return err
}
func (fc *fileCache) Get(ctx context.Context, arg Item) (*CachedStream, error) {
@@ -110,14 +114,15 @@ func (fc *fileCache) Get(ctx context.Context, arg Item) (*CachedStream, error) {
log.Trace(ctx, "Cache MISS", "cache", fc.name, "key", key)
reader, err := fc.getReader(ctx, arg)
if err != nil {
+ r.Close()
+ w.Close()
+ _ = fc.invalidate(ctx, key)
return nil, err
}
go func() {
if err := copyAndClose(w, reader); err != nil {
log.Debug(ctx, "Error storing file in cache", "cache", fc.name, "key", key, err)
- if err = fc.invalidate(ctx, key); err != nil {
- log.Warn(ctx, "Error removing key from cache", "cache", fc.name, "key", key, err)
- }
+ _ = fc.invalidate(ctx, key)
} else {
log.Trace(ctx, "File successfully stored in cache", "cache", fc.name, "key", key)
}