From 1399e0fc9fc31fb37f772860a74bc862e78058ea Mon Sep 17 00:00:00 2001 From: Radhi Fadlillah Date: Tue, 6 Aug 2019 20:51:06 +0700 Subject: [PATCH] Fix: archive is never closed --- internal/webserver/server.go | 6 ++++++ pkg/warc/writer.go | 1 + 2 files changed, 7 insertions(+) diff --git a/internal/webserver/server.go b/internal/webserver/server.go index 56637ed..8cfb18a 100644 --- a/internal/webserver/server.go +++ b/internal/webserver/server.go @@ -6,6 +6,7 @@ import ( "time" "github.com/go-shiori/shiori/internal/database" + "github.com/go-shiori/shiori/pkg/warc" "github.com/julienschmidt/httprouter" cch "github.com/patrickmn/go-cache" "github.com/sirupsen/logrus" @@ -24,6 +25,11 @@ func ServeApp(DB database.DB, dataDir string, port int) error { ArchiveCache: cch.New(time.Minute, 5*time.Minute), } + hdl.ArchiveCache.OnEvicted(func(key string, data interface{}) { + archive := data.(*warc.Archive) + archive.Close() + }) + // Create router router := httprouter.New() diff --git a/pkg/warc/writer.go b/pkg/warc/writer.go index de0daef..d0a6a3b 100644 --- a/pkg/warc/writer.go +++ b/pkg/warc/writer.go @@ -54,6 +54,7 @@ func NewArchive(req ArchivalRequest, dstPath string) error { if err != nil { return fmt.Errorf("failed to create archive: %v", err) } + defer db.Close() // Create archiver arc := &archiver.Archiver{