Skip to content

Commit 3dfbfca

Browse files
committed
feat: improve stale temp directories background cleanup
1 parent 6004fc6 commit 3dfbfca

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

local/php/executor.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,22 @@ func (e *Executor) Config(loadDotEnv bool) error {
292292
}
293293

294294
func (e *Executor) CleanupTemporaryDirectories() {
295-
go cleanupStaleTemporaryDirectories(e.Logger)
295+
backgroundCleanup := make(chan bool, 1)
296+
go cleanupStaleTemporaryDirectories(e.Logger, backgroundCleanup)
297+
296298
if e.iniDir != "" {
297299
os.RemoveAll(e.iniDir)
298300
}
299301
if e.tempDir != "" {
300302
os.RemoveAll(e.tempDir)
301303
}
304+
305+
// give some room to the background clean up job to do its work
306+
select {
307+
case <-backgroundCleanup:
308+
case <-time.After(100 * time.Millisecond):
309+
e.Logger.Debug().Msg("Allocated time for temporary directories to be cleaned up is over, it will resume later on")
310+
}
302311
}
303312

304313
// The Symfony CLI used to leak temporary directories until v5.10.8. The bug is
@@ -307,7 +316,10 @@ func (e *Executor) CleanupTemporaryDirectories() {
307316
// in-use by running servers we can't simply delete the parent directory. This
308317
// is why we make our best to find the oldest directories and remove then,
309318
// cleaning the directory little by little.
310-
func cleanupStaleTemporaryDirectories(mainLogger zerolog.Logger) {
319+
func cleanupStaleTemporaryDirectories(mainLogger zerolog.Logger, doneCh chan<- bool) {
320+
defer func() {
321+
doneCh <- true
322+
}()
311323
parentDirectory := filepath.Join(util.GetHomeDir(), "tmp")
312324
mainLogger = mainLogger.With().Str("dir", parentDirectory).Logger()
313325

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy