StringHttpMMessageConverter not closing input stream and leaks file handle

Viewed 51

I am using rest controller post method with below params

@RequestPart("meta-data") String meta @RequestPart("file") MultipartFile file

the String parameter is being used by StringHttpMessageConverter which is opening a new input stream , the underlying tomcat container is using FileInputStream to open the file handle to upload_xxxx.tmp file. This file handle is never closed within the convertor class and thus leaks file handle everytime a new request is made.

The problem is not there with Jackson Convertors where the JSONParser is closing the streams.

Any suggestions on how to fix this? Using @RequestParam instead of @RequestPart seems to work fine but as per spring documentation @RequestPart is recommended. But I have issue with the open file handles.

0 Answers
Related