You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Massive increase in memory usage between 12.1.8 and 12.1.10 caused by ZipFileSystems #15228
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
But with Jetty 12.1.10 the memory is full with ZipFileSystems
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);
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
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).
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
This is what gets set as resources on the ResourceFactories after that change
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 WebAppContexttempDirectory 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).
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.
Activity
[-]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[/+]joakime commentedon Jun 3, 2026
ZipFileSystemis a JVM class.There was a bug with Jetty 12.1.8 and older where the
ZipFileSystemwe used was not owned by us (typical java resource issue).This was fixed in Jetty 12.1.9, now every
newResource()has it's ownZipFileSystem(if the Path or URL isjar:file://).First thing I would change with your code snippet is to create a single
ResourceFactoryand and use it multiple times.Don't create a new
ResourceFactoryper resource (that's quite wasteful).Something like this ...
ekupcik commentedon Jun 3, 2026
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
This is what gets set as resources on the ResourceFactories after that change
Or actually there were some with 12.1.8. But "just" a few less
ekupcik commentedon Jun 3, 2026
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.
ekupcik commentedon Jun 3, 2026
And just opening a few more pages in my app makes it explde completely
joakime commentedon Jun 3, 2026
With the information provided here, I'm unable to replicate.
Do you have a project you can share that can replicate this issue?
joakime commentedon Jun 3, 2026
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/resourcesasZipFileSystem, intentionally.It will use the
WebAppContexttempDirectoryto expand those resources into a temp directory to serve without theZipFileSystem. 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).ekupcik commentedon Jun 3, 2026
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.
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
joakime commentedon Jun 3, 2026
That code path is useful to see. Thank you.
I'm going to try a few things to see if I can replicate.
joakime commentedon Jun 4, 2026
I think I was able to replicate in a test case, and come up with a fix.
newResource()during webapp started phase. #15231Would you be able to build/test from that PR and see if it helps you?
ekupcik commentedon Jun 4, 2026
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.
19 remaining items
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request
Move Jetty to 12.1.12: 12.1.10 leaks a zip filesystem mount per request