001.jpeg file being used by another process

My supervisor is receiving the following error when trying to save an open document to an XML file prior to converting to PDF:


mscorlib error ‘80070020’

The process cannot access the file ‘D:\ReverseOrigination\DocSets\Tmp\TmpMergeDoc.001.jpeg’ because it is being used by another process.

/Includes/DocSetCreatorEnd.asp, line 8


Our ASP software uses the ComHelper to merge documents into one document then convert that document to PDF. The error occured at the final stage of converting to .doc to .pdf.
ASP code is attached.

Hello!
Thank you for asking this.
I found that 8th line in the ASP file is the following:
mergeDoc.Save_4 strTmpXmlFile, 3
It writes intermediate XML and all the images to the disk. Every file is accessed only once in this operation. So if you get such an error then one of the image files existed previously and was held by some process.
Normally if you have this line of code Aspose.Pdf should delete image files after it has completed the conversion:
oAsposePdf.IsImagesInXmlDeleteNeeded = True
But if something went wrong you might have the mentioned file undeleted and locked. Please check this manually browsing the folder and if the file exists trying to delete it.
The other reason you can get this error has multithreaded nature. If your server handles two requests simultaneously and file names coincide then one thread might try to access (say overwrite) file just created by another one.
I see the code synthesizing file names for the files:
strTmpPdfFile = strPdfDocSetPath & LoanNumber & “.pdf”
strTmpXmlFile = strPdfDocSetTmpPath & “TmpMergeDoc.xml”
Can you guarantee that these names are always unique? It may be possible that two requests are related to the same load contract and you get identical LoanNumber for both threads. Please check this too.
Let us know if you find the solution or if you can provide additional information so we could help you further.
Regards,

I believe that the second reason could be what’s going wrong. There might have been multiple users trying to use that directory and file at the same time.

Okay. That could be fixed if you provide anything unique for the file names. There is no possibility to use simple incremental counter in ASP but you can get current time including milliseconds, generate GUID or take some guaranteed unique parameters from the request itself. This is up to you.
Note that multithreaded issues are difficult to spot because of their intermittent reproducibility. It’s better to proof everything theoretically rather then catch the bugs immediately before the product release.
P.S. Also if several users request the same report with considerable frequency/probability you can cache responses to optimize performance of you server on the conversion. Of course you would manage data coherence and suggest how long to keep them if you choose this way. But this isn’t related to Aspose components.
Have a nice day,

OK. I made the change so the file is unique. I’m using the session id in the filename, but after a successful conversion I’m seeing the 001.jpeg file undeleted. The 002.jpeg file and the .xml file are all being deleted, but not the first 001.jpeg and that file remains undeleted unless I physically delete it.

Here’s a screen print.

Wow. That’s strange. We don’t make any special processing for the image number 001. Really.
Let’s clarify the following:

  1. Is this reproduced every time you run your server or only from time to time?
  2. Could it exist from the previous runs? (It’s uncertainly because you include session ID to its name.)
  3. Is there any error(s) while the request is being processed?
  4. Does the system always allow you to delete the file manually or not?
    This last issue might be specific to your environment. Can you give me any else hint?
    Thank you,
  1. Is this reproduced every time you run your server or only from time to time? Almost every time, but once the 001.jpeg file is left behind it’s always left behind.
  2. Could it exist from the previous runs? (It’s uncertainly because you include session ID to its name.) Yes, but even staying on the same session I still see the file undeleted. My boss keeps adding each 001.jpeg file per session, so for him the list keeps growing.
  3. Is there any error(s) while the request is being processed? Sometime the 001.jpeg cannot be delete and the error says the file is being used by some other process.
  4. Does the system always allow you to delete the file manually or not? No. Sometimes I have to reset the web server, or logoff of the session and log back in before I can delete it.
    I wish I had more ideas, but this is very strange.

Do you mean your boss uses some incremental counter within every session and gets the list growing? I agree that’s weird.
Please add statements “obj = Nothing” after you finish using particular objects in the code to release them explicitly. COM interoperability objects can stay in memory and hold any resources. That’s the magic of Microsoft so I would try to make object dismissal a bit more evident.
If that doesn’t help, please try the same but with altered documents. For instance you can put docs with dogs’ pictures to the server and get them randomly for conversion and retrieval with considerable server load of course.
Another thing we can try is deploying your web service on our side and performing some testing.
Good luck,

Yes, our ASP code has a variable called SessionId which is unique everytime someone logs on, and each time we run the Word - Pdf conversion process there’s a FileName_[SessionId].001.jpeg left over.
Just finished adding “Set obj = Nothing” commands at the end of my process, but still having the same problem with the leftover jpeg file for each session.
The attachment shows the error I get when I try to manual delete the file in question.
I do not understand your suggestion about dog pictures. Please explain in more detail. Have you tried using documents with pictures in them?

Hello!
I see what message it could be if a file being deleted is locked by another process. Thank you.
Of course we tried using documents with pictures. I do this almost every day .Under “pictures with dogs” I mean some kind of test documents we could try to abstract from your application specifics, not literally pets. If we had a permanent problem with any document with pictures we would detect and spot this shortly. So I mean this is highly data-dependent.
The best way at this point is carrying out experiments on our side. Please attach one of the real documents reproducing the issue. You can minimize it removing sensitive or unneeded information but ensure that it still gives this bug in your environment.
If this wouldn’t help, can you provide us a minimal sample based on your application web server which still reproduces this issue? If it takes documents from a database that’s okay, we can remake it slightly to experiment with just local files. Testing the whole project can model aspects related to real site load etc.
Regards,

OK. I made and attached a word document with 4 pictures in it, and when I convert it to PDF I get 4 jpeg files leftover which can not be deleted unless I run IISRESET first. I’ve also included my code and a screen print of the directory where the jgeg files are inside the attachment.

Okay. This can take some more time for experiments. We’ll try to help you.
Thank you,

Please, do what you can.
My code is being held from our production server due to this issue.
Thank you.

Questions:
Can the ComHelper, Aspose.Words, and/or Aspose.Pdf objects be set to clean-up after themselves; or am I the one to make sure the .doc, .xml, .pdf, and even the .jpeg files are all removed at the end of each process, or before beginning a new process?

Hello!
We have discovered that this behavior is a regression in Aspose.Pdf library version 3.6.1.0. As a workaround please try Aspose.Pdf 3.6.0.0. This one works fine making all necessary cleanup. I’ll contact Aspose.Pdf team with this issue. I’m very sorry for them.
Thank you,

Thank you, version 3.6.0.0 works great.
And thanks for contacting the Aspose.Pdf team.

Will the issue be logged?
Please notify me when the fix is released.

Of course it will be logged and you will be notified when it is fixed. But it is to be done by Aspose.Pdf team. I already wrote them and their PM promised to take a look. It’s severe enough to disappoint many customers. But from my experience such bugs are usually easy to fix.
Regards,

Hi,

The problem has been resolved. Please try the attachment before our new hotfix.
Sorry for inconvenience.

Best regards.