Skip to content

feat: improve stale temp directories background cleanup #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions local/php/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down