Bug 575426 - ZipFile leak during org.eclipse.jdt.ui.tests.packageview.ContentProviderTests3
Summary: ZipFile leak during org.eclipse.jdt.ui.tests.packageview.ContentProviderTests3
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.21   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 4.21 M3   Edit
Assignee: Jörg Kubitz CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2021-08-16 02:55 EDT by Jörg Kubitz CLA
Modified: 2021-08-19 02:20 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Kubitz CLA 2021-08-16 02:55:46 EDT
Andrey Loskutov reported in bug 571614#c15
> Jörg, there are few new regressions in JDT UI tests:
> 
> https://download.eclipse.org/eclipse/downloads/drops4/I20210815-0600/
> testresults/html/org.eclipse.jdt.ui.tests_ep421I-unit-win32-java11_win32.
> win32.x86_64_11.html

All the failing test are from ContentProviderTests3. 

All Errors are either "Could not delete 'C:\jenkins_agent\workspace\ep419I-unit-win32-java11-new\workarea\I20210815-0600\eclipse-testing\test-eclipse\eclipse\jdt_folder\TestProject1\mylib.jar'."
or "Resource '/TestProject1/mylib.jar' already exists". The later seem to be a follow up error from the first error.

=> the root error during delete was "The process cannot access the file because it is being used by another process."

(This sounds similar to bug 573363)
Something has still a file handle open to that jar.
I retried the test several times. When i put a breakpoint at LocalFile.internalDelete() i was sometimes able to reprduce the error. 
Some timing issue? I took a heapdump at that state and analysed it in the OQL Console:
select {instance: s, content: s.toString()} from java.lang.String s
    where s.toString().contains("mylib")

There where 2 GC roots for the filehandle:

--
path in java.io.RandomAccessFile#68 : C:\Users\JKubitz\eclipseDev\jdt\junit-workspace\TestProject1\mylib.jar
zfile in java.util.zip.ZipFile$Source#65
zsrc in java.util.zip.ZipFile$CleanableResource#64
action in jdk.internal.ref.CleanerImpl$PhantomCleanableRef#101
discovered in jdk.internal.ref.CleanerImpl$PhantomCleanableRef#60
next in jdk.internal.ref.CleanerImpl$PhantomCleanableRef#61 [GC root - JNI global]
--
path in sun.nio.fs.WindowsPath#335
filePath in java.io.File#362 : C:\Users\JKubitz\eclipseDev\jdt\junit-workspace\TestProject1\mylib.jar
file in java.util.zip.ZipFile$Source$Key#65
key in java.util.HashMap$Node#82287
[150] in java.util.HashMap$Node[]#6587 : 256 items
table in java.util.HashMap#4951
static files in class java.util.zip.ZipFile$Source [GC root - sticky class] : ZipFile$Source
--
Both GC roots point to a ZipFile.
I further put a conditional breakpoint at ZipFile. And there where only 3 stacktraces that opend that file:
Thread [main] (Suspended (breakpoint at line 228 in ZipFile))	
	owns: RunnableLock  (id=2053)	
	JavaModelManager.getZipFile(IPath, boolean) line: 2896	
	JavaModelManager.getZipFile(IPath) line: 2865	
	JavaModelManager.verifyArchiveContent(IPath) line: 2846	
	ClasspathEntry.validateLibraryContents(IPath, IJavaProject, String) line: 2514	
	ClasspathEntry.validateLibraryEntry(IPath, IJavaProject, String, IPath, String, boolean) line: 2440	
	ClasspathEntry.validateClasspathEntry(IJavaProject, IClasspathEntry, IClasspathContainer, boolean, boolean) line: 2303	
	ClasspathEntry.validateClasspathEntry(IJavaProject, IClasspathEntry, boolean, boolean) line: 2174	
	ClasspathValidation.validate() line: 75	
	SetClasspathOperation(ChangeClasspathOperation).classpathChanged(ClasspathChange, boolean) line: 55	
...

Thread [main] (Suspended (breakpoint at line 228 in ZipFile))	
	owns: RunnableLock  (id=2053)	
	JavaModelManager.getZipFile(IPath, boolean) line: 2896	
	JavaModelManager.getZipFile(IPath) line: 2865	
	ClasspathEntry.getManifestContents(IPath) line: 1016	
	ClasspathEntry.getCalledFileNames(IPath) line: 1043	
	ClasspathEntry.resolvedChainedLibraries(IPath, HashSet, ArrayList) line: 983	
	ClasspathEntry.resolvedChainedLibraries(IPath) line: 970	
	ClasspathEntry.resolvedChainedLibraries() line: 1673	
	JavaProject.resolveClasspath(IClasspathEntry[], IClasspathEntry[], boolean, boolean) line: 3303	
	JavaProject.resolveClasspath(JavaModelManager$PerProjectInfo, boolean, boolean) line: 3414	
	JavaProject.getResolvedClasspath() line: 2498	
	ExternalFolderChange.updateExternalFoldersIfNecessary(boolean, IProgressMonitor) line: 42	
	SetClasspathOperation(ChangeClasspathOperation).classpathChanged(ClasspathChange, boolean) line: 63	
	SetClasspathOperation.executeOperation() line: 78	
	SetClasspathOperation(JavaModelOperation).run(IProgressMonitor) line: 740	
...
Daemon Thread [Java indexing] (Suspended (breakpoint at line 228 in ZipFile))	
	ZipFile.<init>(File, int, Charset) line: 228	
	ZipFile.<init>(File, int) line: 177	
	ZipFile.<init>(File) line: 191	
	AddJarFileToIndex.execute(IProgressMonitor) line: 150	
	IndexManager(JobManager).run() line: 432	
	Thread.run() line: 834	

=> 2 Stacktraces in "main" thread. And 1 "Java indexing".
Either the main threads somhow leaks ZipFile or "Java indexing" leaks it or still holds it.
Comment 1 Eclipse Genie CLA 2021-08-16 08:34:18 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/184069
Comment 2 Jörg Kubitz CLA 2021-08-16 08:49:23 EDT
There was also a call to getArchiveValidity which leaked getZipFile if the test ran for more then 120seconds.
Comment 3 Andrey Loskutov CLA 2021-08-16 09:25:34 EDT
(In reply to Jörg Kubitz from comment #2)
> There was also a call to getArchiveValidity which leaked getZipFile if the
> test ran for more then 120seconds.

This is actually a regression in 4.21, via bug 571340, caused by the old code from bug 455042 not properly working for *bad* jars now to leak also "valid" jars.
Comment 5 Andrey Loskutov CLA 2021-08-17 04:05:03 EDT
Thanks Jörg.
Comment 6 Manoj N Palat CLA 2021-08-19 02:20:31 EDT
Verified with Eclipse 4.21 M3 Version: 2021-09 (4.21) Build id: I20210818-1800
[by code check]