Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 488128

Summary: JavaReconciler: Too many open files
Product: [Eclipse Project] JDT Reporter: Brian de Alwis <bsd>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED WORKSFORME QA Contact:
Severity: critical    
Priority: P3 CC: stephan.herrmann
Version: 4.2   
Target Milestone: 4.6 M6   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
List of open files on first too-many-open-files exception
none
stack trace
none
console output; interrupted as I killed the runtime none

Description Brian de Alwis CLA 2016-02-19 14:15:56 EST
Created attachment 259836 [details]
List of open files on first too-many-open-files exception

Build-Id: 4.6.0.I20160216-1400
Running Java 1.8.0_72 and _74
OS X 10.10.5

I've had 5 workspaces toasted in 5 days due to 'java.io.FileNotFoundException: . . .: (Too many open files)'.  This is (unfortunately) entirely reproducible.  I do have a large number of features installed here.

I attached the file-leak-detector (http://file-leak-detector.kohsuke.org) and it reports 985 of 1104 files are open by the JavaReconciler thread.

jstack only shows a single JavaReconciler thread (so different from bug 257545).

Starting a new workspace is ok for a while.

I've attached a jstack output (taken when the too-many-open-files messages were flying out), the open-file table reported by the file-leak-detector on first too-many-open-files error, and the console output too.  I can provide the workspace too if that helps (it's ~330MB)
Comment 1 Brian de Alwis CLA 2016-02-19 14:16:19 EST
Created attachment 259837 [details]
stack trace
Comment 2 Brian de Alwis CLA 2016-02-19 14:17:43 EST
Created attachment 259838 [details]
console output; interrupted as I killed the runtime

Note that the first too-many-open-files occurs about 20 seconds after launching.
Comment 3 Brian de Alwis CLA 2016-02-19 14:43:05 EST
Bumping to critical: when this occurs, it kills my workspace (and doesn't help with productivity).

I'm now running my workspace with the file-leak-detector's http server, and it looks like I consistently have about 126 open files open.

Huh, I do a search (Ctrl-Shift-G) and that can trigger the problem.

I guess one thing that I've been doing differently recently is using 'Add all plug-ins to the search path'.  I do have 1091 bundles in my …/plugins/ directory, and my ulimit is 1024.  Hmmm…
Comment 4 Brian de Alwis CLA 2016-02-19 14:49:32 EST
The number of open files seems to stabilize after the Ctrl-Shift-G.

My suspicion is that I'm doing some searches while platform.resources is attempting to persist information out to the workspace from a build, which fails due to the too-many-open-files.  (I exacerbate the situation as I regularly use a search tool called Ferret [1] that automatically runs many many Java searches.)

[1] https://github.com/briandealwis/ferret
Comment 5 Brian de Alwis CLA 2016-02-19 16:41:01 EST
After committing some changes (from the command-line), I had some refreshing of the workspace and then saw the following spat on the console.  Now having resolving problems: this workspace's short lifetime has come to an end.


!ENTRY org.eclipse.egit.ui 4 0 2016-02-19 16:33:37.273
!MESSAGE Failed to refresh projects from index changes
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Errors occurred while refreshing resources with the local file system.
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.refreshResource(FileSystemResourceManager.java:959)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.refresh(FileSystemResourceManager.java:942)
	at org.eclipse.core.internal.resources.Resource.refreshLocal(Resource.java:1594)
	at org.eclipse.egit.ui.Activator$ResourceRefreshJob$1.run(Activator.java:452)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
	at org.eclipse.egit.ui.Activator$ResourceRefreshJob.run(Activator.java:437)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Contains: The project description file (.project) for 'org.eclipse.intro.theme.solstice-feature' is missing.  This file contains important information about the project.  The project will not function properly until this file is restored.
!SUBENTRY 1 org.eclipse.core.resources 4 271 2016-02-19 16:33:37.273
!MESSAGE Errors occurred while refreshing resources with the local file system.
!SUBENTRY 2 org.eclipse.core.resources 4 567 2016-02-19 16:33:37.274
!MESSAGE The project description file (.project) for 'org.eclipse.intro.theme.solstice-feature' is missing.  This file contains important information about the project.  The project will not function properly until this file is restored.

!ENTRY org.eclipse.egit.ui 4 0 2016-02-19 16:33:37.351
!MESSAGE Failed to refresh projects from index changes
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Errors occurred while refreshing resources with the local file system.
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.refreshResource(FileSystemResourceManager.java:959)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.refresh(FileSystemResourceManager.java:942)
	at org.eclipse.core.internal.resources.Resource.refreshLocal(Resource.java:1594)
	at org.eclipse.egit.ui.Activator$ResourceRefreshJob$1.run(Activator.java:452)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
	at org.eclipse.egit.ui.Activator$ResourceRefreshJob.run(Activator.java:437)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Contains: The project description file (.project) for 'org.eclipse.ui.intro.solstice' is missing.  This file contains important information about the project.  The project will not function properly until this file is restored.
!SUBENTRY 1 org.eclipse.core.resources 4 271 2016-02-19 16:33:37.351
!MESSAGE Errors occurred while refreshing resources with the local file system.
!SUBENTRY 2 org.eclipse.core.resources 4 567 2016-02-19 16:33:37.351
!MESSAGE The project description file (.project) for 'org.eclipse.ui.intro.solstice' is missing.  This file contains important information about the project.  The project will not function properly until this file is restored.

!ENTRY org.eclipse.egit.ui 4 0 2016-02-19 16:33:37.355
!MESSAGE Failed to refresh projects from index changes
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Errors occurred while refreshing resources with the local file system.
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.refreshResource(FileSystemResourceManager.java:959)
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.refresh(FileSystemResourceManager.java:942)
	at org.eclipse.core.internal.resources.Resource.refreshLocal(Resource.java:1594)
	at org.eclipse.egit.ui.Activator$ResourceRefreshJob$1.run(Activator.java:452)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
	at org.eclipse.egit.ui.Activator$ResourceRefreshJob.run(Activator.java:437)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Contains: The project description file (.project) for 'org.eclipse.ui.intro.solstice.examples' is missing.  This file contains important information about the project.  The project will not function properly until this file is restored.
!SUBENTRY 1 org.eclipse.core.resources 4 271 2016-02-19 16:33:37.355
!MESSAGE Errors occurred while refreshing resources with the local file system.
!SUBENTRY 2 org.eclipse.core.resources 4 567 2016-02-19 16:33:37.355
!MESSAGE The project description file (.project) for 'org.eclipse.ui.intro.solstice.examples' is missing.  This file contains important information about the project.  The project will not function properly until this file is restored.

!ENTRY org.eclipse.jdt.core 4 4 2016-02-19 16:33:37.945
!MESSAGE Exception while updating project references
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Could not set the project description for 'org.eclipse.ui.intro.solstice' because the project description file (.project) is out of sync with the file system.
	at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1246)
	at org.eclipse.jdt.internal.core.ProjectReferenceChange$1.run(ProjectReferenceChange.java:108)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
	at org.eclipse.jdt.internal.core.ProjectReferenceChange.updateProjectReferencesIfNecessary(ProjectReferenceChange.java:111)
	at org.eclipse.jdt.internal.core.DeltaProcessor.resourceChanged(DeltaProcessor.java:2119)
	at org.eclipse.jdt.internal.core.DeltaProcessingState.resourceChanged(DeltaProcessingState.java:477)
	at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:299)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:289)
	at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:152)
	at org.eclipse.core.internal.resources.Workspace.broadcastBuildEvent(Workspace.java:360)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
!SUBENTRY 1 org.eclipse.core.resources 4 274 2016-02-19 16:33:37.945
!MESSAGE Could not set the project description for 'org.eclipse.ui.intro.solstice' because the project description file (.project) is out of sync with the file system.

!ENTRY org.eclipse.jdt.core 4 4 2016-02-19 16:33:37.947
!MESSAGE Exception while updating project references
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Could not set the project description for 'org.eclipse.ui.intro.solstice.examples' because the project description file (.project) is out of sync with the file system.
	at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1246)
	at org.eclipse.jdt.internal.core.ProjectReferenceChange$1.run(ProjectReferenceChange.java:108)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2240)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2267)
	at org.eclipse.jdt.internal.core.ProjectReferenceChange.updateProjectReferencesIfNecessary(ProjectReferenceChange.java:111)
	at org.eclipse.jdt.internal.core.DeltaProcessor.resourceChanged(DeltaProcessor.java:2119)
	at org.eclipse.jdt.internal.core.DeltaProcessingState.resourceChanged(DeltaProcessingState.java:477)
	at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:299)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:289)
	at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:152)
	at org.eclipse.core.internal.resources.Workspace.broadcastBuildEvent(Workspace.java:360)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
!SUBENTRY 1 org.eclipse.core.resources 4 274 2016-02-19 16:33:37.947
!MESSAGE Could not set the project description for 'org.eclipse.ui.intro.solstice.examples' because the project description file (.project) is out of sync with the file system.
Comment 6 Stephan Herrmann CLA 2016-02-19 17:18:24 EST
Looking at the typical stack from attachment 259836 [details]:

#1 /usr/local/installs/e4-dev/Eclipse.app/Contents/Eclipse/plugins/org.eclipse.wst.html.ui.infopop_1.0.201.v201409111852.jar by thread:org.eclipse.jdt.internal.ui.text.JavaReconciler on Fri Feb 19 13:48:20 EST 2016
	at java.util.zip.ZipFile.<init>(ZipFile.java:150)
	at java.util.zip.ZipFile.<init>(ZipFile.java:163)
	at org.eclipse.jdt.internal.core.JavaModelManager.getZipFile(JavaModelManager.java:2749)
	at org.eclipse.jdt.internal.core.JavaModelManager.getZipFile(JavaModelManager.java:2715)
	at org.eclipse.jdt.internal.core.util.Util.getJdkLevel(Util.java:848)
	at org.eclipse.jdt.internal.core.JarPackageFragmentRoot.computeChildren(JarPackageFragmentRoot.java:80)
	at org.eclipse.jdt.internal.core.JavaProjectElementInfo.initializePackageNames(JavaProjectElementInfo.java:253)
	at org.eclipse.jdt.internal.core.JavaProjectElementInfo.getProjectCache(JavaProjectElementInfo.java:226)
	at org.eclipse.jdt.internal.core.JavaProject.getProjectCache(JavaProject.java:1924)
	at org.eclipse.jdt.internal.core.JavaProjectElementInfo.newNameLookup(JavaProjectElementInfo.java:310)
	at org.eclipse.jdt.internal.core.JavaProject.newNameLookup(JavaProject.java:2329)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.<init>(SearchableEnvironment.java:60)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.<init>(SearchableEnvironment.java:67)
	at org.eclipse.jdt.internal.core.CancelableNameEnvironment.<init>(CancelableNameEnvironment.java:26)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:178)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:271)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:191)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:724)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:790)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1250)


We are inside this block in CompilationUnit.reconcile():

	try {
		manager.cacheZipFiles(this); // cache zip files for performance (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=134172)
		op.runOperation(monitor);
	} finally {
		manager.flushZipFiles(this);
	}

Only during this operation are all zip files kept open (see the try-finally in Util.getJdkLevel() which closes the zip immediately if caching is not explicitly enabled).

This indicates that the burst of open files appears just during initializing one ProjectCache. 

I'm not sure how PDE implements 'Add all plug-ins to the search path', but if they do this by adding all those jars to the build path of each project, then we may have a hard limit here: ulimit must be significantly higher than the number of plugins.

OTOH, we may want to figure out, under which circumstances Util.getJdkLevel() should perhaps bypass the zip caching. If this is the only access to a given jar then we should better close it, but we may not know in advance ...

BTW: any specific reason to keep such a low ulimit? On my ubuntu box the default seems to be "unlimited".
Comment 7 Brian de Alwis CLA 2016-02-19 17:33:45 EST
I have tried boosting the ulimit but OS X doesn't seem to want to allow it.

$ ulimit -n 2048
-bash: ulimit: open files: cannot modify limit: Operation not permitted
Comment 8 Brian de Alwis CLA 2016-02-23 10:52:54 EST
So it turns out I had a 'ulimit -n 1024' in my .bashrc (blush).  I'm sure that seemed like a large number a decade ago.

Closing as WORKSFORME.
Comment 9 Stephan Herrmann CLA 2016-02-23 12:13:28 EST
(In reply to Brian de Alwis from comment #8)
> Closing as WORKSFORME.

Thanks for letting us know.