logo

Clearing Up Domino's Temporary Files

There's been a thorn in my side recently in that Domino has been leaving temporary files on the server and causing my code to break. The code emailed out PDF invoices, which are supposed to have my customer's logo on, but, because the code break, they didn't. It's all a bit embarrassing really for both parties involved.

The PDF file is generated by a Java Agent. To embed their logo in it it looks for a "setting" document which has the image file attached to it. It then get an InputStream so it can read the file in to "memory", like so:

EmbeddedObject eo = document.getAttachment(filesname);
InputStream is = eo.getInputStream();

You can see the same approach in use here (note the image in the resulting PDF -- it's from a document in the DB).

Now, at the point we call getInputStream() Domino creates a temporary file in the server's temp folder. It's name is something like eo12345678tm. This is where the problems start, as the names of these files don't appear to be random enough to ensure there isn't a conflict of names in those that don't get cleared up.

The problem is that, if Domino tries to create a temp file and one of the name it's trying to create already exists it just fails. Worse still it seems to remember this file's name ready for the next time you try to call getInputStream(). Again it will fail. It will keep failing until you go in there and clear out the temp files.

Having cleared out the folder once only for it to happen again I went looking for the solution. Luckily Julian had documented the issue. The solution is simple -- add a call to the recycle() method of the EmbeddedObject. Doh!! Turns out it was my fault all along.

So I added the fix to my code and breathed a sigh of relief. Things seemed to be working again. One less thing to worry about.

Not so quick! It soon happened again. What I'd neglected to do was clear up the existing temp files from the server after adding the fix. It was only a matter of time before server tried to write a temp file with the name of one those left behind and got itself stuck in a rut again.

To solve this I wrote a quick agent to remove all the temp files (I don't have shell access). Here it is:

Sub RemoveTempFiles
    Dim pathName As String, fileName As String, tmpFolder As String
    tmpFolder = "C:\Windows\Temp\"
    pathName = tmpFolder + "eo*tm" 'E.g: eo1989832343tm
    fileName = Dir(pathName, 0)
    On Error Goto failed
    Do While fileName <> ""
        Kill tmpFolder + fileName
nextFile:        
        fileName = Dir()
    Loop 
    Exit Sub
failed:
    Call LogEvent("Can't delete temp file - " + fileName, 2, Nothing)
    Resume nextFile
End Sub

Hopefully this will help somebody out at some point.

Comments

    • avatar
    • Jas
    • Thu 9 Apr 2009 04:24 AM

    I have was hit by a similar problem after I used the file download servlet. I then wrote a scheduled agent to run on daily basis to delete such files.

  1. In this case (when extracting attachments from notes document using java) remember to call

    eo.recycle().

    This will perform the correct cleanup action and remove temporary files.

    • avatar
    • Ferdy
    • Thu 9 Apr 2009 09:22 AM

    Funny, even before I read the full description of your problem I thought "recycle!". It seems to be a fix for so many Java problems in Domino.

    I recall a few years ago at work some order processing code would hang up the server every few weeks. It was a subtle memory leak that caused it, due to...you guessed it...recycle.

    Those who do Java in Domino be warned. You need to know about recycle, when to use it, in WHAT ORDER to use it.

  2. Yeah, as Ferdy says recycle anything that domino's and if you've got jar files for iText or similar stick them in Lotus\Domino\jvm\lib\ext - not whatever you do in the agent.

    • avatar
    • Mark C
    • Wed 15 Apr 2009 09:00 AM

    Jake, any chance you can expand on your domino to PDF work? I have a project that I have been procrastinating on whereby I need to take several back end docs and meld them together into an invoice. I have iText going, but it seems like a major pain to produce the finished PDF (needs formatting and images and page counts [1 of x]...)

    thnx,

  3. BTW Jake, iText RTF is out there, so we can all make word (well RTF files) on Linux at without all of that formatting hell. - Hooray.

    Similar but not quite as complete as iText PDF, but not bad at all.

    • avatar
    • Jake Howlett
    • Wed 13 May 2009 04:12 PM

    Note: After adding the fix mentioned here to the Java *script library* I was using I was stumped when it fixed the issue on my dev server but not on the live server for my client. Clutching at straws I finally found the answer by re-saving the agent itself on the live server.

    It seems that each agent remembers the last file it tried to create and keeps on trying to create that same file and failing over and over (why, why, why!). Even deleting all the files using the code I posted above won't fix this. It seems the only fix is to resave the agent and make it start afresh.

    • avatar
    • Stepan K
    • Thu 17 Dec 2009 04:49 AM

    Hi Jake,

    I'm currently stuck with the same issue. Sometimes when I call RichTextItem.embedObject(); domino creates temporary file which name is something like eoXXXXtm. I haven't found any way to delete it programatically. I've tried to recycle the returned EmbeddedObject, call update on the RichTextItem or to save the parent document. None of it have worked. Can you help me please?

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Thu 9 Apr 2009

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content