Skip to content
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

Temporary files leak RESTserver / Windows7 #1767

Open
dizzzz opened this issue Mar 12, 2018 · 36 comments
Open

Temporary files leak RESTserver / Windows7 #1767

dizzzz opened this issue Mar 12, 2018 · 36 comments
Labels
awaiting-response requires additional information from submitter windows issues specific to windows

Comments

@dizzzz
Copy link
Member

dizzzz commented Mar 12, 2018

What is the problem

While testing #1766 I found a lot of old existSRVxxxxxxxxxxxx.tmp files inside the newly defined tmp directory. These are written by org.exist.http.RESTServer#doPut

What did you expect

The nr of tmp files should not increase.

Describe how to reproduce or add a test

Use HTTP PUT to push XML documents (larger than 64k) to the eXist-db REST interface,

To verify: it might be a windows specific issue. Note #1702

Context information

Please always add the following information

  • eXist-db version + Git Revision hash e.g. eXist-db 4,0
  • Java version: Java8u161
  • Operating system: Windows 7
  • 64 bit
  • start database via YAJSW
@dizzzz dizzzz added bug issue confirmed as bug discuss ask for feedback investigate issues being looked at labels Mar 12, 2018
@alebastrov
Copy link

alebastrov commented Mar 14, 2018

We have that issue unfixed in our 2.2 (+ our modifications) version. They are left in cases we could not recognize. At least they count on finalizers as far as I know, that's why it needs to be changed (finalizers are not supposed to be used as normal data flow)
It does not depend on windows platform, we have the same on linux one
P.S. size of files also does not matter.

@dizzzz
Copy link
Member Author

dizzzz commented Mar 16, 2018

by design, for eXist-db version 3+, for existSRVxxxxxxxxxxxx.tmp the size should matter as under a certain limit (40k?64k? the document is entirely bufferend in memory, hence no document is written to disk....

what are the exact filename patterns you see?

@duncdrum duncdrum added the YAJSW In light of upcoming changes… label Apr 17, 2019
@jking527467
Copy link

Was there every anything done in regards to this? In my current system it seems every XML document being stored in eXist is creating a temporary file that's never cleaned up causing for 100's of GB's worth of data building up and tanking the heap space eventually.

@dizzzz
Copy link
Member Author

dizzzz commented May 29, 2019

I think that recent work of @reinhapa fixed this issue: #2621

@jking527467
Copy link

Awesome, this isn't in any released version right? I'd have to move forward with the develop-4.x.x branch?

@jking527467
Copy link

Actually, looks like it made it into https://github.com/eXist-db/exist/releases/tag/eXist-4.7.0

@jking527467
Copy link

I've upgraded to eXist 4.7.0 and I still see an issue. Basically a *.tmp file gets created for each XML Resource I create using the XML RPC endpoint and the *.tmp files never go away. When are these supposed to go away during the normal lifecycle?

@adamretter
Copy link
Contributor

@jking527467 I assume you are operating on Windows? If so this issue might shed some light for you - #1863

@jking527467
Copy link

jking527467 commented May 29, 2019

@adamretter - I don't see any errors in retrieval of the temp files in the logs, I just see a file get created each time a post happens : [29/May/2019:19:29:43 +0000] "POST /exist/xmlrpc HTTP/1.1" 200 159

I am operating on Windows and my code exists in a WAR file deployed inside Wildfly. The eXist DB is installed on a separate server and I'm posting to the xmlrpc endpoint. I see logging statements with items being removed in the eXist logs. The *.tmp files are being created on the server where my application is deployed in Wildfly.

[qtp566760932-62] INFO (NativeBroker.java [removeXMLResource]:2553) - Removing document TSS-L0642513-1 (1624) ...

@reinhapa
Copy link
Member

The #2621 is currently for read operations for remote resources only. Due same issues while heavy writing lots of small files to a remote resource, I'm looking into using the same mechanism of buffering data within memory up to 4 MB also for write operations right know. (But both seems not be related to you're issue)

@adamretter
Copy link
Contributor

adamretter commented May 29, 2019

@jking527467 Sure, so when you send data via XML-RPC to eXist-db, it needs to be cached somewhere before it is ingested. The temp files are used to do this.

We have historically had problems with deleting temp files on WIndows. This can be due to 1 of 3 reasons:

  1. MemoryMapped file and NIO are mixed on the same temp file. This results in a bug within the JVM on Windows that is outside our control. This bug stops us from being able to close the file, and therefore we cannot delete it. We can work around this though, by not mixing the two types of IO on the same file.

  2. Some Windows process (e.g. Virus Scanner etc) is reading the temp files, which stops us from being able to delete them when we are finished with them.

  3. We are leaking file handles for the temp files. This would be a bug in our code...

Regards (1) and (3) I spent quite some time auditing and fixing such cases in the past. That is not to say we don't have an issue or a regression... Have you seen this issue with recent eXist-db versions prior to 4.7.0?

@jking527467
Copy link

jking527467 commented May 29, 2019

@adamretter - I'd assume that for 1 and 2 I'd see errors somewhere that shows that these files cannot be deleted. I cannot locate those such errors.

We upgraded from a very old version of eXist (1.4.2) to 4.3.1 as part of a response to a security audit that required us to upgrade Java versions, add a username and password, etc. The same issue was happening in 4.3.1 which prompted me to upgrade to 4.7.0 where I still see it happening.

This did not happen in 1.4.2 though I'm sure the entire cache mechanism was overhauled.

@adamretter
Copy link
Contributor

@jking527467 how are your temp files named?

@jking527467
Copy link

I just started the application and it created a folder named :
exist-db-temp-file-manager-5210439493760754392

The files are named :
exist-db-temp-18072172457871596.tmp

There is one file for each resource that I'm trying to save and each time I save a resource I get a new file.

@reinhapa
Copy link
Member

@adamretter @jking527467 I can take a look into it. Just to be shure: your eXist-db version is 4.7.0 right?

@jking527467
Copy link

Yes, I saw the same behavior in 4.3.1 as well. I've made different configurations of the java.io.tmpdir and always see the same behavior. I also tried using different InputStreamCache classes but I don't seem to think that's helping.

@jking527467
Copy link

FYI the reason I found the file situation was through YourKit and a growing number of java.lang.ref.Finalizer objects.

image

@adamretter
Copy link
Contributor

@jking527467 So the next step is to find which part of the codebase is creating the files (via the TemporaryFileManager), from there we can determine if we are closing the files correctly and/or if some external process is interfering with them.

@reinhapa
Copy link
Member

@jking527467 @adamretter I did some local rework on the TemporaryFileManager in order to no longer relay on the in the meantime deprecated finalize() method for removing files in one shutdown hook thread.

I seems that there is at least a correct call to clean up the temporary file being called after the upload. It is maybe possible, that the stream is still open upon calling the cleanup method for the temp file... I will check that Monday on a Windows instance...

@jking527467
Copy link

jking527467 commented Jun 3, 2019

@reinhapa Did you submit a PR for this? I'm interested in trying it out.

I also discovered that this does not happen on our instance that has not yet been upgraded. The instance has eXist 4.3.1 deployed but the software interacting with eXist is using the 1.4.1 eXist core library and xmldb 1.4.1 api. That instance also does not use a username and password to communicate with the eXist database. On that instance I can't even find temp files that have been created.

@reinhapa
Copy link
Member

reinhapa commented Jun 3, 2019

@jking527467 I created a bugfix branch on my exist repo for it and need to test it now on my Windows VM,,,

@jking527467
Copy link

Awesome, thanks. Just curious if you were able to reproduce the issue I'm seeing?

@reinhapa
Copy link
Member

reinhapa commented Jun 3, 2019

@jking527467 On my windows 8.1 VM there where no problems. File was created and deleted immediately after processing...

You can enable debug logging for the TemporaryFileManager by adding the following lines to you're log4j2.xml

 <Logger name="org.exist.util.io.TemporaryFileManager" additivity="false" level="debug">
        <AppenderRef ref="exist.core"/>
</Logger>

@jking527467
Copy link

So in the 4.7.0 baseline you cannot reproduce what I'm seeing? Unfortunately we're on Windows Server 2008 R2 so I don't know if that makes a difference.

@reinhapa
Copy link
Member

reinhapa commented Jun 3, 2019

@jking527467 just added a new update to properly delete old temp folders too. Also further tests did not reveal any problems on Windows. I would like that you test the current version and send me the exist.log containing the TemporaryFileManager entries that may show up...

@jking527467
Copy link

I will test with 4.7.0 with the logging changes and follow up with you.

@jking527467
Copy link

@reinhapa I wanted to follow up with you because I found a setup where I am not experiencing the issue.

Our instance has eXist 4.3.1 deployed and the software interacting with eXist is using the 2.2 eXist core library and xmldb 1.4.1 api. Files are being created and immediately deleted using this setup. I have not had time to incrementally upgrade the eXist core library to determine where it stops working, but I thought this may give you some more insight on what to look for.

@reinhapa
Copy link
Member

reinhapa commented Jun 8, 2019

@jking527467 I'm looking forward to hear from your results.

@adamretter
Copy link
Contributor

@dizzzz @jking527467 Can we get an update for @reinhapa's work please?

@dizzzz
Copy link
Member Author

dizzzz commented Jun 24, 2019

I did a bulk upload with HTTP/PUT (as originally in my report), and monitored files like "exist-db-temp-8021125833792001398.tmp" (macOS).

commands for XML and non XML documents: :

for i in `seq 1 10000`; do curl http://localhost:8080/exist/rest/db/tmp/aaa$i.txt --upload-file conf.txt; echo $i;  done ;

and

for i in `seq 1 10000`; do curl http://localhost:8080/exist/rest/db/tmp/bbb$i.xml --upload-file conf.xml; echo $i;  done ;

Run in parallel; all temp files are removed as expected. For me, the issue is not present anymore.

Configuration:

  • macOS
  • 4.8.0-SNAPSHOT / 4XX branch
  • Java 1.8.0_212

I do not have a windows7 box around; Maybe I can find a windows10 box.

Please note that @jking527467 's report is about running the WAR file inside WILDFLY which I have never tested.

@dizzzz
Copy link
Member Author

dizzzz commented Jun 24, 2019

when reading the thread I see something a bit annoying: my original issue was reported on the PUT method, not with an XMLRPC interface. Mixing up things makes a thread not readable :-(

in addition, running 1.4.1 client JARS with a 4.3 server: please don't. Why would you do this?

@dizzzz dizzzz added awaiting-response requires additional information from submitter windows issues specific to windows and removed YAJSW In light of upcoming changes… bug issue confirmed as bug discuss ask for feedback investigate issues being looked at labels Jun 24, 2019
@duncdrum
Copy link
Contributor

any news @jking527467

@dizzzz
Copy link
Member Author

dizzzz commented Aug 27, 2019

Two months later... let’s close it in a week or so.

@jking527467
Copy link

jking527467 commented Aug 27, 2019 via email

@dizzzz
Copy link
Member Author

dizzzz commented Aug 28, 2019

Thnx for your reply. I suspect that the changes should fix the issue. I think that it is essential to have server and client side the same versions of the code; that is what we test , other combinations... not :/

@jking527467
Copy link

jking527467 commented Aug 28, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-response requires additional information from submitter windows issues specific to windows
Projects
None yet
Development

No branches or pull requests

6 participants