ArgumentOutOfRangeException in Document.Save

An ArgumentOutOfRangeException can occur when there are multiple
threads doing Document.Save at the same time. The stack trace is always the same.

The attached C# project
runs Open/Save on the same document 100 times. It does that with 1 thread, then 2 threads, then 4 threads. A new Document object is created for each Open/Save, objects are not reused or shared. Exceptions are logged to the log.txt file. See attached log.txt for output from a sample run on a quad core. Notice that there are no exceptions when only 1 thread is used, there are several exceptions with 2 threads, and there are many exceptions with 4 threads. The number of exceptions changes in each run, so it is clearly a race condition. I’ve only tested with a quad-core processor. I imagine the problem is
less repeatable with dual-core and possibly not repeatable with
single-core.

Although this sample project does Document.Save to a MemoryStream, the same problem occurs when writing to files. This sample project uses the same document each time, because it makes for a simpler test case and is more likely to reproduce the error, but I originally discovered the problem when processing a large queue of unique documents.

Hi
Thanks for your request. I cannot reproduce eth problem on my side. Which version of Aspose.Words do you use? To check version of the library, right click on the dll, select Properties from the context menu, then select Version tab. You will see File version.
I use the latest version of Aspose.Words for testing. You can download it from here:
https://releases.aspose.com/words/net
Best regards.

You built and ran this sample project and checked the bin/Debug/log.txt file and it did not report any exceptions? The exceptions are easily repeatable for me with version 7.0.0 and 8.0.0 and in x86 and x64 modes.

How many processors does your test machine have? It must have at least 2 processors to reproduce the issue. If I limit the process to a single processor, then it runs without exceptions:

Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(1);

But if I allow the process to use at least 2 processors, then I get lots of exceptions:

Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(3);

Because it is a concurrency issue (probably some static variables being used during Save), you might need to test it on a different machine that has more/faster processors. I’m do not know if this is reproducible on a single-core with HyperThreading, but I have reproduced using this test program with Aspose.Words version 8.0.0 on:

i7 860 @ 2.8 GHz
Core 2 6700 @ 2.67 GHz

Hi Robert,

Thank you for additional information. You are right, I tested with single CPU. I managed to reproduce the problem once I run test on Core 2. Your request has been linked to the appropriate issue. You will be notified as soon as the problem is resolved.

Best regards.

Has this been fixed?

Hi Robert,
Thanks for your inquiry. I just checked the issue once again using the latest version of Aspose.Words. And it seems the problem does not occur. Could you please check and confirm whether the issue still remains with the latest version.
You can download the latest version of Aspose.Words from here:
https://releases.aspose.com/words/net
Best regards.

Not fixed. The error is actually WORSE in 9.0 than in 8.0. See the attached log files from two runs within a few minutes of each other on the same hardware using version 8.0 and 9.0.

I tested each of the SaveFormat options and the errors are only reproducible with SaveFormat.Doc. Surprisingly, SaveFormat.Docm does not report any errors.

To produce these log files, I did this:

Using the sample project (ConcurrencyErrorDuringSave) that I provided earlier I placed Aspose.Words.dll version 8.0 into the project folder, rebuilt the project, ran it, and renamed the log.txt file to log-8.0.txt (10 KB). Then I placed Aspose.Words.dll version 9.0 into the project folder, rebuilt the project, ran it, and renamed the log.txt file to log-9.0.txt file (22 KB). I repeated this several times to be sure. Each time, version 9.0 produced more concurrency exceptions than 8.0.

Again… this only occurs on machines with more than one processing core, but that is very common in server environments.

Hi

Thank you for additional information. I added your request into my monthly report. This will push the issue up in the priority list. I will let you know once there is some progress with this issue. My apologizes for inconvenience.

Best regards.

The issues you have found earlier (filed as 11933) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.