🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Fixed the enduring nasty "too many files open" bug!! Fix #446
Deluan452c8dc44bff
diff --git a/utils/cache/file_caches.go b/utils/cache/file_caches.goindex 3be6b4fe1..b09d303c8 100644--- a/utils/cache/file_caches.go+++ b/utils/cache/file_caches.go@@ -121,6 +121,7 @@ func (fc *fileCache) Get(ctx context.Context, arg Item) (*CachedStream, error) {return &CachedStream{Reader: sr,Seeker: sr,+ Closer: r,Cached: true,}, nil} else {@@ -135,11 +136,15 @@ func (fc *fileCache) Get(ctx context.Context, arg Item) (*CachedStream, error) {type CachedStream struct {io.Readerio.Seeker+ io.CloserCached bool}func (s *CachedStream) Seekable() bool { return s.Seeker != nil }func (s *CachedStream) Close() error {+ if s.Closer != nil {+ return s.Closer.Close()+ }if c, ok := s.Reader.(io.Closer); ok {return c.Close()}diff --git a/utils/cache/file_caches_test.go b/utils/cache/file_caches_test.goindex 8332af67f..c8f94cd06 100644--- a/utils/cache/file_caches_test.go+++ b/utils/cache/file_caches_test.go@@ -60,6 +60,7 @@ var _ = Describe("File Caches", func() {s, err := fc.Get(context.TODO(), &testArg{"test"})Expect(err).To(BeNil())Expect(s.Cached).To(BeFalse())+ Expect(s.Closer).To(BeNil())Expect(ioutil.ReadAll(s)).To(Equal([]byte("test")))// Second call is a HIT@@ -68,6 +69,7 @@ var _ = Describe("File Caches", func() {Expect(err).To(BeNil())Expect(ioutil.ReadAll(s)).To(Equal([]byte("test")))Expect(s.Cached).To(BeTrue())+ Expect(s.Closer).ToNot(BeNil())Expect(called).To(BeFalse())})