Skip to content

Massive increase in memory usage between 12.1.8 and 12.1.10 caused by ZipFileSystems #15228

Description

@ekupcik

Jetty version(s)
12.1.10

Jetty Environment
ee10

Java version/vendor (use: java -version)
21

OS type/version
Windows 11

Description
Im am running an embedded Jetty that starts multiple WebAppContext programattically. The applications themselves are using JSPs and .tag file based tags. In the IDE everything is served from the filesystem but in production everything is bundled in the JAR files.

When I updated from jetty 12.1.8 to 12.1.10 (cannot say anything about 12.1.9 because of the windows related bug in that version) my builds no longer worked and crashed with OOM errors after clicking on a few pages. The whole server is configured to run with 512MB which is not that much but more than enough for running in production and the static memory usage with 12.1.8 is something like 110MB and there is nothing relevant Jetty related in memory

Image

But with Jetty 12.1.10 the memory is full with ZipFileSystems

Image

The whole setup in my code is a bit complex. First i determine which JARs and directories belong to each of the WebAppContexts and then everything goes to

for(String loResource : aWebApp.getResources() )
		{
			String loPrepareResourcePath = prepareResourcePath(loResource);
			if(loPrepareResourcePath != null)
			{
				org.eclipse.jetty.util.resource.Resource loNewResource =  ResourceFactory.of(loWebAppContext).newResource(loPrepareResourcePath);
				if(loNewResource != null)
				{
					loResources.add(loNewResource);
				}
				else
				{
					LOG.error("Failed to create web module resource for "+loPrepareResourcePath);
				}
			}
		}
		for (String loUri : loWebModuleJars)
		{
			org.eclipse.jetty.util.resource.Resource loNewClassPathResource = ResourceFactory.of(loWebAppContext).newResource(loUri);
			if(loNewClassPathResource != null)
			{
				loResources.add(loNewClassPathResource);
			}
			else
			{
				LOG.error("Failed to create web module resource for "+loUri);
			}
		}

		org.eclipse.jetty.util.resource.Resource loResourceCollection = ResourceFactory.combine(loResources);
		loWebAppContext.setBaseResource(loResourceCollection);

Activity

  1. added
    Bug
    on Jun 3, 2026
  2. changed the title [-]Massive increase in memory usage between 12.1.8 and 12.1.10[/-] [+]Massive increase in memory usage between 12.1.8 and 12.1.10 caused by ZipFileSystems[/+] on Jun 3, 2026
  3. joakime commented on Jun 3, 2026

    @joakime
    Contributor

    ZipFileSystem is a JVM class.
    There was a bug with Jetty 12.1.8 and older where the ZipFileSystem we used was not owned by us (typical java resource issue).
    This was fixed in Jetty 12.1.9, now every newResource() has it's own ZipFileSystem (if the Path or URL is jar:file://).

    First thing I would change with your code snippet is to create a single ResourceFactory and and use it multiple times.
    Don't create a new ResourceFactory per resource (that's quite wasteful).

    Something like this ...

    ResourceFactory resourceFactory = ResourceFactory.of(webappContext);
    List<Resource> resources = new ArrayList<>();
    
    for(String entry: app.getResources())
       resources.add(resourceFactory.newResource(entry);
    for(String entry: app.getJars())
       resources.add(resourceFactory.newResource(entry);
       
    Resource baseResource = ResourceFactory.combine(resources);
    webappContext.setBaseResource(baseResource);
  4. ekupcik commented on Jun 3, 2026

    @ekupcik
    Author

    Thansk for the advice. It improves it but doesn't really solve the general problem that the ZipFileSystem instances that were not present at all in the heapdump with 12.1.8 are still there. Though there are fewer of them

    Image

    This is what gets set as resources on the ResourceFactories after that change

    oejur.ResourceFactoryInternals$LifeCycle@30e9ca13{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-7.7.1-SNAPSHOT.jar!/META-INF/resources
    oejur.ResourceFactoryInternals$LifeCycle@30e9ca13{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-module-admin-7.7.1-SNAPSHOT.jar!/META-INF/resources
    oejur.ResourceFactoryInternals$LifeCycle@12fcc71f{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-module-useradmin-7.7.1-SNAPSHOT.jar!/META-INF/resources
    oejur.ResourceFactoryInternals$LifeCycle@12fcc71f{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-module-admin-7.7.1-SNAPSHOT.jar!/META-INF/resources
    oejur.ResourceFactoryInternals$LifeCycle@12fcc71f{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-7.7.1-SNAPSHOT.jar!/META-INF/resources
    oejur.ResourceFactoryInternals$LifeCycle@3c87e6b7{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-7.7.1-SNAPSHOT.jar!/META-INF/resources
    oejur.ResourceFactoryInternals$LifeCycle@3c87e6b7{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-module-idp-7.7.1-SNAPSHOT.jar!/META-INF/resources
    oejur.ResourceFactoryInternals$LifeCycle@6f94a5a5{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-7.7.1-SNAPSHOT.jar!/META-INF/resources
    oejur.ResourceFactoryInternals$LifeCycle@6f94a5a5{STARTED} jar:file:/U:/Projects/usu-gatekeeper/out/distributions/gatekeeper-7.7.1-SNAPSHOT/server/lib/usu-gatekeeper-module-api-7.7.1-SNAPSHOT.jar!/META-INF/resources
    

    Or actually there were some with 12.1.8. But "just" a few less

    Image
  5. ekupcik commented on Jun 3, 2026

    @ekupcik
    Author

    What I can see in the dump is for example this. this _input.taglibs.tag is a file that gets included in other jsp tags.

    Image Image
  6. ekupcik commented on Jun 3, 2026

    @ekupcik
    Author

    And just opening a few more pages in my app makes it explde completely

    Image Image
  7. joakime commented on Jun 3, 2026

    @joakime
    Contributor

    With the information provided here, I'm unable to replicate.
    Do you have a project you can share that can replicate this issue?

  8. joakime commented on Jun 3, 2026

    @joakime
    Contributor

    Out of curiosity, why are you building up the Base Resource like that?
    Why not let Jetty itself handle all of that via the WebAppContext.setExtraClassPath()?

    For example, Jetty will not mount jar:file///path/to/.jar!/META-INF/resources as ZipFileSystem, intentionally.
    It will use the WebAppContext tempDirectory to expand those resources into a temp directory to serve without the ZipFileSystem. This is partly done for performance reasons, and also to help Apache JSP and Apache JSTL use the resources natively as well (without going through the Jetty Resource layer).

  9. ekupcik commented on Jun 3, 2026

    @ekupcik
    Author

    Good question. This code has been migrated over many Jetty versions over 21 years...

    I am able to reproduce the problem in my IDE by loading the resources from the build JARs instead of the filesystem.

    Image Image Image Image Image Image

    Maybe i am blind, but from getResourceAsStream to mounted.add there is no "did i handle that resource before?" and always "register this new resource"

    The requested resource URLs are nothing special

    Image
  10. joakime commented on Jun 3, 2026

    @joakime
    Contributor

    That code path is useful to see. Thank you.
    I'm going to try a few things to see if I can replicate.

  11. moved this to 🏗 In progress in Jetty 12.1.11 - FROZENon Jun 3, 2026
  12. self-assigned this
    on Jun 3, 2026
  13. joakime commented on Jun 4, 2026

    @joakime
    Contributor

    I think I was able to replicate in a test case, and come up with a fix.

    Would you be able to build/test from that PR and see if it helps you?

  14. ekupcik commented on Jun 4, 2026

    @ekupcik
    Author

    Looks good as far as i can tell. I now have just 9 ZipFilesystem instances in memory which corresponds to the calls to resourceFactory.newResource() my initialization code.

  15. 19 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions