From eeb4da5d0f512048b0230ef69330f4aa45dac173 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 10 Oct 2024 19:22:13 +0200 Subject: [PATCH] explictly run garbage collection after loading credentials Decrypting the credentials requires a lot of memory, such that later garbage collections only happen after doubling that memory usage again. Explictly run a GC to reset the memory usage reference level. --- cmd/calendarsync/main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/calendarsync/main.go b/cmd/calendarsync/main.go index 7275768..3cb4ac6 100644 --- a/cmd/calendarsync/main.go +++ b/cmd/calendarsync/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "runtime" "time" "github.com/inovex/CalendarSync/internal/auth" @@ -180,6 +181,12 @@ func Run(c *cli.Context) error { } log.Info("loaded sink adapter", "adapter", cfg.Sink.Adapter.Type, "calendar", cfg.Sink.Adapter.Calendar) + // By default go runs a garbage collection once the memory usage doubles compared to the last GC run. + // Decrypting the storage in NewSourceAdapterFromConfig/NewSinkAdapterFromConfig requires a lot of memory, + // such that the next GC only trigger once the memory usage double compared to that peak. Explicitly trigger + // a GC to reset the memory usage reference level. + runtime.GC() + if log.GetLevel() == log.DebugLevel { for _, transformation := range cfg.Transformations { log.Debug("configured transformer", "name", transformation.Name, "config", transformation.Config)