Skip to content

Tomcat does not create temporary directory used to store file uploads when it does not exist #9616

@shehzadgee

Description

@shehzadgee

Steps to Reproduce
When spring boot application starts with default value of server.tomcat.basedir in application.properties. It creates two folders in /tmp folder. /tmp/tomcat.xxxxx/.. and /tmp-docbase.xxxx/

These directories are used to save temp files during multipart upload among other needed functions. In production system such as Centos, by default system is configured to delete all /tmp files if not touched for 10 days. Once this file is deleted logs will show this error and upload will fail with following exception

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [**/tmp/tomcat.1220970741172837513.8080/work/Tomcat/localhost/ROOT]** is not valid
	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:111)

Possible Solution:
May be lets check if required temp directory doesn't exist recreate during multipart upload. And upload will work without any additional settings.
Other fixes/suggestions are welcome as well.

Affected Versions
Logs are from Spring Boot v1.4.3.RELEASE but its still same in 1.5.3.RELEASE

Workarounds

  • On Centos 7 update tmp.conf in following three directories /etc/tmpfiles.d/, /run/tmpfiles.d/ and /usr/lib/tmpfiles.d/. with following line
    x /tmp/tomcat*

OR handle programmatically

  • Catch exception in GlobalException Handler and recreate directory and inform user to try upload again.

full_log.txt

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions