Skip to content

Retrieving static resource via ServletContext root creates (many) jar_cache tmp files #9866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BastiaanProot opened this issue Jul 26, 2017 · 3 comments
Labels
status: duplicate A duplicate of another issue

Comments

@BastiaanProot
Copy link

Since version 1.4.5 we notice our application produces jar_cache*.tmp files. In previous versions it did not. In our case the jar_cache*.tmp files risk filling the disk after a while.

We found the cause:

  1. Locations for static content are auto configured by Spring Boot.
    Default locations for static resources in the resolveChain (in order) are:
    • (ServletContext) /
    • classpath:/META-INF/resources/
    • classpath:/resources/
    • classpath:/static/
    • classpath:/public/
  2. In version 1.4.4 getting a resource from ServletContext root returned instances of EmptyResource and getUrl() returned null. So the ServletContext location got skipped and then resources were retrieved from classpath:/META-INF/resources/. This changed in version 1.4.5: Resource handling is inconsistent across different embedded containers #8299. ServletContext now returns a valid URL to the resource.
  3. Our static resources are contained in a jar in our application jar. So jar-in-jar. (URL to the resource looks like this: jar:war:file:application.jar*/BOOT_INF/lib/resources.jar!/META-INF/resources/favicon.ico) Retrieving the static resource requires JVM to use jar_cache*.tmp files. (using File.deleteOnExit). This seems to occur when you do resource.contentLength().
    On Debian/OpenJDK we can only see these jar_cache*.tmp files using lsof; they are open but deleted files. These do not get released until the application exits. So they still take up space and fill the disk. Similarly on Windows/SunJDK we can see the jar_cache*.tmp files accumulate and they are only deleted when the application exits. This seems to be a known/old phenomenon with the JVM.

In short:

Due to changes in the behaviour of ServletContext static resources our application now performs jar-in-jar lookups and accumulates tmp files.

Our solution:

We used the spring.resources.static-locations application property to customize the order of the locations and put classpath:/META-INF/resources/ first.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 26, 2017
@wilkinsona wilkinsona marked this as a duplicate of #9751 Jul 26, 2017
@wilkinsona
Copy link
Member

@BastiaanProot Thank you very much for the detailed analysis. We'd already seen the symptom you've described in #9751 but were some distance away from identifying the cause.

I see that you've mentioned EmptyResource so I assume that you're using Tomcat. Can you please confirm that's the case?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jul 26, 2017
@BastiaanProot
Copy link
Author

Indeed, we're using embedded Tomcat.

@wilkinsona wilkinsona removed the status: waiting-for-feedback We need additional information before we can continue label Jul 28, 2017
@wilkinsona
Copy link
Member

The default ordering has been changed in 9dd3fb7 that closed #9240.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants