From 3dfbfcacf9f858561586f9ac9319c102ff8213a7 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Fri, 14 Feb 2025 16:00:30 +0100 Subject: [PATCH] feat: improve stale temp directories background cleanup --- local/php/executor.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/local/php/executor.go b/local/php/executor.go index 91d384cd..b3123788 100644 --- a/local/php/executor.go +++ b/local/php/executor.go @@ -292,13 +292,22 @@ func (e *Executor) Config(loadDotEnv bool) error { } func (e *Executor) CleanupTemporaryDirectories() { - go cleanupStaleTemporaryDirectories(e.Logger) + backgroundCleanup := make(chan bool, 1) + go cleanupStaleTemporaryDirectories(e.Logger, backgroundCleanup) + if e.iniDir != "" { os.RemoveAll(e.iniDir) } if e.tempDir != "" { os.RemoveAll(e.tempDir) } + + // give some room to the background clean up job to do its work + select { + case <-backgroundCleanup: + case <-time.After(100 * time.Millisecond): + e.Logger.Debug().Msg("Allocated time for temporary directories to be cleaned up is over, it will resume later on") + } } // The Symfony CLI used to leak temporary directories until v5.10.8. The bug is @@ -307,7 +316,10 @@ func (e *Executor) CleanupTemporaryDirectories() { // in-use by running servers we can't simply delete the parent directory. This // is why we make our best to find the oldest directories and remove then, // cleaning the directory little by little. -func cleanupStaleTemporaryDirectories(mainLogger zerolog.Logger) { +func cleanupStaleTemporaryDirectories(mainLogger zerolog.Logger, doneCh chan<- bool) { + defer func() { + doneCh <- true + }() parentDirectory := filepath.Join(util.GetHomeDir(), "tmp") mainLogger = mainLogger.With().Str("dir", parentDirectory).Logger()