Skip to content

Add CleanupMode with retries/ignoring failures #5396

@kwin

Description

@kwin

Sometimes cleaning up temp directories on Windows fails with the following exception:

org.junit.platform.commons.JUnitException: Failed to close extension context
	at java.util.ArrayList.forEach(ArrayList.java:1259)
	at java.util.ArrayList.forEach(ArrayList.java:1259)
Caused by: java.io.IOException: Failed to delete temp directory C:\Users\RUNNER~1\AppData\Local\Temp\junit-4423183114217413878. The following paths could not be deleted (see suppressed exceptions for details): <root>, minimal-skin.jar
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.util.ArrayList.forEach(ArrayList.java:1259)
	at java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
	at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
	at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:483)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485)
	... 2 more
	Suppressed: java.nio.file.DirectoryNotEmptyException: C:\Users\RUNNER~1\AppData\Local\Temp\junit-4423183114217413878
		at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:266)
		at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
		at java.nio.file.Files.delete(Files.java:1126)
		at java.nio.file.Files.walkFileTree(Files.java:2688)
		at java.nio.file.Files.walkFileTree(Files.java:2742)
		... 13 more
	Suppressed: java.nio.file.FileSystemException: C:\Users\RUNNER~1\AppData\Local\Temp\junit-4423183114217413878\minimal-skin.jar: The process cannot access the file because it is being used by another process.

		at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
		at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
		at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
		at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269)
		at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
		at java.nio.file.Files.delete(Files.java:1126)
		at java.nio.file.Files.walkFileTree(Files.java:2670)
		at java.nio.file.Files.walkFileTree(Files.java:2742)
		... 13 more
		Suppressed: java.nio.file.FileSystemException: C:\Users\RUNNER~1\AppData\Local\Temp\junit-4423183114217413878\minimal-skin.jar: The process cannot access the file because it is being used by another process.

(experienced in https://github.com/apache/maven-doxia-sitetools/actions/runs/22283165952/job/64457060989?pr=610).

This happens most probably because the temporary file (in this case a JAR) is still scanned by MS Defender which keeps that file open and therefore prevents it from being deleted. Although one could argue this is an issue of Windows it would be nice there would be two new clean up modes:

  1. ALWAYS_IGNORING_FAILURE, same as ALWAYS but just logging any exceptions (i.e. not failing the build)
  2. ALWAYS_WITH_RETRIES, same as ALWAYS but retries several times after sleeping in case of exceptions

An ever better way would be to configure these aspects separately from the condition in a new attribute like CleanupMethod. That way,

  1. the default,
  2. ignore failure,
  3. with retries

could be combined with any of the conditions (although for NEVER they obviously wouldn't be applicable).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions