gnodet opened a new pull request, #354:
URL: https://github.com/apache/maven-clean-plugin/pull/354

   ## Problem
   
   `BackgroundCleaner.scanForLeftovers()` scans the fast staging directory at 
session start and queues any leftover directories for background deletion. It 
did not protect against the case where **two concurrent builds share the same 
staging directory**: one build's leftover scan could delete directories that 
are actively being used by the other build.
   
   Fixes #353.
   
   ## Fix
   
   Introduce a `LEFTOVER_AGE_THRESHOLD_MS` constant (30 seconds). 
`scanForLeftovers()` now reads the last-modified time of each staged directory 
and **skips any directory younger than the threshold**.
   
   - A directory created by an ongoing concurrent build will always be younger 
than 30 s at the time of the scan (the `BackgroundCleaner` is initialised very 
early in the session, so there is no practical way a live build's staged 
directories are 30 s old at that point).
   - A directory left behind by a killed build will be older than 30 s in 
virtually all cases.
   - If `getLastModifiedTime()` fails (unlikely), the directory is also skipped 
— conservative, safe default.
   
   An age filter was chosen over the alternative PID-marker approach because:
   - It requires no additional file I/O on the hot path (only during the 
leftover scan at session start).
   - It is robust on all platforms (no `/proc` or OS-specific PID checks).
   - The 30-second threshold is conservative enough to make false negatives 
(live directory treated as leftover) virtually impossible.
   
   ## Also fixed
   
   A pre-existing missing closing `}` in 
`CleanerTest.batchRetryLogsWarningAfterRetryWhenStillFailing` that was causing 
a compile error on the spotless/checkstyle phase.
   
   ## Tests
   
   Two new tests in `BackgroundCleanerTest`:
   - `scanForLeftoversSkipsRecentDirectories` — a directory with `lastModified 
= now` is **not** deleted.
   - `scanForLeftoversDeletesOldDirectories` — a directory with `lastModified = 
now − threshold − 60 s` **is** deleted.
   
   The existing `scanForLeftoversDeletesOrphanedDirectories` test is updated to 
set an old timestamp on the leftover directory (it would have been skipped by 
the new age filter with the default `lastModified = now` from 
`createDirectory`).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to