Free Support Forum - aspose.com

Multithread processing (one thread, one file) is killing documents (saved with 0 bytes)

Hi Aspose team,

before I had problem that when I open in multiple threads different documents some of them were saved with 0 bytes.

Today, I experienced same case.
In prepared project you will find under video folder what was happening. Basically, I have 88 documents that I wanted to proces in parallel (of course, not all at once). Sample application pulled first few files, made changes and started to save documents back. As files are named in order like 1.one, 2.one until 88.one processing started from smallest to largest number and you’ll see that initially opened documents like 2,4,… were at the end not properly saved (result: 0 bytes).

Processed documents are in debug/docs/OneNote and backup files so that you can try few times are in debug/docs folder.

Challenging is that this is not happening always but it is something what can be created. Easier is to close and run application every time when you copy source files from debug/docs to debug/docs/OneNote.

As project is big I am uploading to my server and will share download link with assigned expert.

Thanks,
Oliver

Important remark: after application finished I left video recoding for additional 30 seconds to see if some save is still pending but nothing changed and files stayed on 0 bytes.

In addition complete processing of 88 documents was around 1:30 minutes so those 30 additional seconds were more than enough to have save process completed if it was ongoing and, affected documents, were among first ones opened for processing so they had almost 2 minutes to be saved.

Of course, I was using latest version of Aspose.Note components.

@dr.doc,
Thank you for your query.

Please take your time to share the compilable complete solution which can be compiled and executed here without any missing reference. We will reproduce the scenario here and provide our feedback accordingly.

@dr.doc
Although the issue is not reproduced but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as
NOTENET-3073 – Random 0 Bytes file created while updating the OneNote files in multithreaded environment

Hi Aspose team,

I tried same with latest version of Aspose.Note (20.5) and still had the same problem. First run after I upgraded from 20.3 to 20.5 killed one document, then I tried 2 runs and all was ok.

As additional tests I was playing with value of MaxDegreeOfParallelism:

  • initial run was with 8 (number of my cores)
  • when I changed to 10, 3 documents were corrupted
  • change to 20, 1 document was corrupted
  • change to 15, 5 documents were corrupted

Basically, first run after MaxDegreeOfParallelism (line 17 in Form1 code) was always killing documents.
In attached zip file you can find videos for each of runs.

It would be great to have somebody checking on your side when parallelism is changed.

OneNote.KillingDocuments2.zip (6.0 MB)
OneNote.KillingDocuments1.zip (5.5 MB)

This is really ugly bug as files are completelly killed when saved with Aspose.Notes.

Thanks,
Oliver

Here is also error message that I got when documents became corrupted:

OneNote_0bytes.zip (286.8 KB)

Also here StackTrace:

at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at Aspose.Note.Fonts.FontsSubsystem.GetFontFamily(String fontName) at .(String , Single , FontStyle , ) at .() at .(Char ) at .(String ) at .(String , Single , TextStyle , IList1 , HorizontalAlignment , Single , )
at Aspose.Note.RichText.(Single )
at Aspose.Note.RichText.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF )
at Aspose.Note.CompositeNode1.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF ) at Aspose.Note.CompositeNode1.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF )
at Aspose.Note.Outline.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF )
at Aspose.Note.Page.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF )
at Aspose.Note.Page.()
at Aspose.Note.Page.get_PageLayoutSize()
at . ()
at . ( )
at . ()
at .(Document )
at .(Document , Stream , OneSaveOptions )
at ..(Object )
at .[T](Document , SaveOptions , Action`1 )
at .(Document , Stream , SaveOptions )
at .(Document , String , SaveOptions )
at .(Document , String , SaveFormat )
at Aspose.Note.Document.Save(String fileName, SaveFormat format)
at OneNote.Bugs.Form1.OpenDocumentReplacement(String path, String strFileName, String strDirectoryName, Int64 lngFileSize, Boolean bolIsReadOnly, Boolean wholeWordOnly, Boolean matchCase, Boolean matchWildCards, Boolean useRegex, String regexPatern, Boolean inHyperlinks, Boolean inText, Boolean CreateBackup, String BackupExtension, String extensions, Boolean BackupOnlyChangedDocs, String strOwner) in C:_Projects\Bugs\Aspose\OneNote.Bugs\OneNote.Bugs\Form1.vb:line 98

If you cannot recreate the problem just play with MaxDegreeOfParallelism as almost always when I changed number I got corrupted documents.

@dr.doc,

As this issue is still in progress, so its not resolved in the latest version yet. We have saved your videos for our reference and may refer them while working on this issue.

Regarding the error message, could you please share that when do you get the message shown in the doc file? Is it displayed when you open the 0 byte file in MS OneNote? Please explain it a little bit.

Error message is happening during Doc.Save. Basically, I have
try
doc.save
catch
end try

and error message appears when during Doc.Save execution.

Just change initially share project to:

                Try
                    doc.Save(path, SaveFormat.One)
                Catch ex As Exception
                    MsgBox(path + vbCrLf + ex.Message)
                    MsgBox(ex.StackTrace)
                End Try

Files are before save with normal size (in my case 2-3Mb per file). When save is started exception is happening and save is neve completed thus new file size 0 bytes.

@dr.doc,
Thank you for more explanation. We will consider this information while working on this issue.

Hi,

any news here? This is really ugly issue as documents are killed.

Thx

dr.doc,
This issue is investigated and will be fixed in the coming 20.7 release next month. Moreover, you can use the following workaround for now:

        public void Save(Document document, string path)
        {
            using (var buffer = new MemoryStream())
            {
                document.Save(buffer);
                using (var stream = File.Open(path, FileMode.OpenOrCreate))
                {
                    stream.SetLength(0);

                    buffer.Seek(0, SeekOrigin.Begin);
                    buffer.CopyTo(stream);
                }
            }
        }

Hi,

thanks for quick update.
I tried workaround but it did not work.
Errors are:

An item with the same key has already been added.

at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at Aspose.Note.Fonts.FontsSubsystem.GetFontFamily(String fontName) at .(String , Single , FontStyle , ) at .() at .(Char ) at .(String ) at .(String , Single , TextStyle , IList1 , HorizontalAlignment , Single , )
at Aspose.Note.RichText.(Single )
at Aspose.Note.RichText.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF )
at Aspose.Note.CompositeNode1.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF ) at Aspose.Note.CompositeNode1.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF )
at Aspose.Note.Outline.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF )
at Aspose.Note.Page.6vw7a38rx8hq7gf3sc2fzmpqyry3cca8 (SizeF )
at Aspose.Note.Page.()
at Aspose.Note.Page.get_PageLayoutSize()
at . ()
at . ( )
at . ()
at .(Document )
at .(Document , Stream , OneSaveOptions )
at ..(Object )
at .[T](Document , SaveOptions , Action`1 )
at .(Document , Stream , SaveOptions )
at .(Document , Stream , SaveFormat )
at .(Document , Stream )
at Aspose.Note.Document.Save(Stream stream)
at OneNote.Bugs.Form1.Save(Document document, String path) in C:_Projects\Bugs\Aspose\OneNote.Bugs\OneNote.Bugs\Form1.vb:line 123

Line 123 is document.Save(buffer)

@dr.doc,

Please note, the provided workaround does not prevent throwing the exception. As we told you this issue will be fixed in the coming release which avoids “killing” of the document.

Please wait for the next month’s release.

@dr.doc,

The issues you have found earlier (filed as NOTENET-3073) have been fixed in Aspose.Note for .NET 20.7 update.

Thanks for update.
I just made test and it looks good :slight_smile:

I’ll run few more tests in coming day.

BR,
Oliver

@dr.doc,
You are welcome and take your time to test this release.