Bug 1113338

Summary: [GSS] (6.4.0) DataSourceProvider does not delete the temporary files it creates
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: William Antônio <wsiqueir>
Component: RESTEasyAssignee: Weinan Li <weli>
Status: CLOSED CURRENTRELEASE QA Contact: Katerina Odabasi <kanovotn>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 6.2.2CC: fnasser, kkhan, klape, mkopecky, weli
Target Milestone: DR9   
Target Release: EAP 6.4.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Known Issue
Doc Text:
The `DataSourceProvider` (org.jboss.resteasy.plugins.providers.DataSourceProvider.readDataSource(InputStream, MediaType)) creates a temporary file named `resteasy-provider-datasource ... .tmp` when reading more then 4096 bytes. However, it does not delete the created temporary file itself nor does it provide a facility to do so, resulting in a resource leak. This issue is under investigation and is expected to be resolved in the next release.
Story Points: ---
Clone Of:
: 1122779 (view as bug list) Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1118891, 1122779    
Attachments:
Description Flags
A test for the product none

Description William Antônio 2014-06-26 01:47:28 UTC
Description of problem:
From JIRA: https://issues.jboss.org/browse/RESTEASY-1080

The DataSourceProvider (org.jboss.resteasy.plugins.providers.DataSourceProvider.readDataSource(InputStream, MediaType)) creates a temporary file named "resteasy-provider-datasource ... .tmp" when reading more then 4096 bytes. However, it does not delete the created temporary file itself nor does it provide a facility to do so. This results in a resource leak!


How reproducible:

Easy.

Steps to Reproduce:

There's a reproducer attached to the JIRA for upstream resteasy.

For the product, I'm attaching a reproducer that runs on EAP 6.2
1. Download the reproducer and unzip it
2. Start EAP 6.2 standalone mode, build and deploy the project: 

mvn clean package jboss-as:deploy  -Dmaven.test.skip=true 

3. Run the test

mvn test

Actual results:

After the method execution, the tmp file will still be there;

Expected results:

It should clean the tmp file;

Additional info:

An interceptor would be a possible solution to clean the tmp file right after the JAX-RS method execution.

We could also add a method on the Datasource provider to remove the tmp file, that could be called after the method execution. If you think the interceptor is a good solution, let me know, I have the PR for it.

We could at least add a method on the SequenceDatasource class to remove the temp file:

      public void removeTempFile(){
          tempFile.delete();
      }

Comment 1 William Antônio 2014-06-26 01:48:19 UTC
Created attachment 912312 [details]
A test for the product

A maven project to reproduce the issue on EAP.

Comment 5 JBoss JIRA Server 2014-07-24 00:23:24 UTC
Kyle Lape <kyle.lape> updated the status of jira RESTEASY-1080 to Coding In Progress

Comment 6 Kyle Lape 2014-07-24 21:17:57 UTC
The file is now marked for deletion at the shut down of the JVM.  In addition, the file is deleted immediately once the input stream has reached the end.  

While this commit improvies the behavior of RESTEasy, it does not completely eliminate the potential of a build-up of temporary files.  If a endpoint does not fully consume attachments, then they won't be deleted until the JVM is restarted, which could be a long time.

A potential workaround is to create an EJB timer to delete these files periodically.  I wrote such an EJB here:

https://github.com/kylape/resteasy-datasource-cleaner

Currently waiting for the upstream PRs to be merged.

Comment 7 sgilda 2014-07-31 14:51:57 UTC
Set the requires_doc_text to '-' because this bug targets 6.4 and duplicates the release note text in Bug 1122779, which targets 6.3.1.

Comment 8 Weinan Li 2014-08-28 06:18:44 UTC
Upstream Branch_2_3 fixed: 

master:resteasy-upstream weinanli$ git log 982512d9
commit 982512d99371735d6bce35764962993b0b4a2f98
Author: Kyle Lape <kyle.lape>
Date:   Thu Jul 24 08:41:20 2014 -0700

    [RESTEASY-1080] DataSourceProvider does not delete the temporary files it creates

code reference: https://github.com/resteasy/Resteasy/blob/Branch_2_3/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/providers/DataSourceProvider.java#L133

Comment 9 JBoss JIRA Server 2014-09-16 21:10:04 UTC
Kyle Lape <kyle.lape> updated the status of jira RESTEASY-1080 to Resolved

Comment 10 Katerina Odabasi 2014-09-24 07:50:52 UTC
The fix is not present because resteasy is still in version 2.3.8.Final-redhat-3 not 2.3.9.

Comment 14 Marek Kopecky 2014-11-13 09:25:48 UTC
Verified on EAP 6.4.0.DR9

Comment 15 JBoss JIRA Server 2016-08-02 16:15:28 UTC
Alessio Soldano <asoldano> updated the status of jira RESTEASY-1080 to Closed