Thread Safety on Html To PDF conversion

When attempting to convert HTML to PDF using the Aspose.Pdf.Generator.Pdf object, running two conversions in parallel tasks (each creating their own Pdf object) results in either an ‘Object is currently in use elsewhere’ or ‘key is already present in dictionary’.


Doing the two conversion synchronously converts correctly. The same two conversion using a Task.Run wrapper and awaiting each task, also converts correctly. In both cases, the 1st conversion completes before a new Pdf object is created.

I went through and reviewed this thread:

Object is currently in use elsewhere error

And it appears that Pdf objects should be thread safe.

I’m attaching recreation tests written in Nunit (renamed from .cs to .txt) . I’ve also gone through and made sure to update Aspose.Pdf to the latest version 10.5.1.0 from the nuget packages.

Mike

Hi Mike,


Thanks for contacting support.

I have tested the scenario using code snippet which you have shared and when performing unit tests through NUnit 2.6.3, I did not notice any issue. However the resultant files are not being generated. For your reference, I have also attached my test binaries generated over my end.

Can you please share some further details, which can help us in replicating the issue in our environment. We are sorry for your inconvenience.

Hi Nayyer,


Would it be possible to send me the .csproj file you used to generate UnitTestProject1.dll. I would like to try and replicate your results locally.

Thank you,

Mike

Hi Mike,


Thanks for your inquiry. Sure we will share the project with you shortly.

Best Regards,

Hi Mike,


Sorry for the delayed response.

Please find attached the required project.

Hi Nayyer,


Here is a dropbox link to the project you sent with a few modifications.

https://www.dropbox.com/s/fwofcb8v4lqahuz/UnitTestProject-07022015.zip?dl=0
  1. Included the Aspose.Pdf library as a nuget package

  2. Included NUnit test runner to enable command line running of the tests through the nunit-console-x86.exe.

  3. Included a shell script runtests.cmd to execute 1 passing and 2 error prone unit tests in the UnitTestsProject1.dll. You will need to compile the project to ensure the /bin/debug folder has the UnitTestsProject1.dll present before running runtests.cmd.

I’m still seeing thread related exceptions, however I have to run the tests multiple times to replicate (they may pass during one run and fail during the next). I’ve included specific exception catches in the tests to capture either the “given key was no present in dictionary” or “object in use” errors.

The new project file contains a shell script to run 3 unit tests. You may need to run this script multiple time, or run the script twice in parallel to see the specific exceptions. I’m attaching a two screen shots of the errors that I’m seeing. We also verified this issue occurs on multiple machines.

To summarize:

  1. The two exceptions we see most frequently are ‘object in use’ and ‘given key was not present in the dictionary’. These both occur after calling to an instance of pdf.BindHtml.

  2. The exceptions are not throw every run of the tests. On my machine I had to run the test 2 or 3 times. On a separate machine, the errors would occur on almost every run.

  3. The errors occur intermittently and based on the exception messages coming back, there seems to be some non thread safe access to a dictionary or existing object.

  4. The project is being built with AnyCPU configuration under the .NET 4.5 Framework. I’ve run tests both through ReSharper in Visual Studio, the Nunit GUI console and the nunit command line running x86 version. All with the same intermittent results or pass or fail.

Please let me know if I can provide anymore information.

Thanks

Mike

Hi Mike,


Thanks for sharing the resource files.

We are testing the scenario using latest resource files and will get back to you soon.

Are there any updates to this issue?

Hi Mike,


Sorry for the delayed response.

I am still working on replicating the issue using shared project and will share my findings shortly.

Hi Mike,


I have tested the scenario and have observed that in a subsequent attempt to perform conversion, an exception Object is currently in use elsewhere is being generated. For
the sake of correction, I have logged it in our issue tracking system as
PDFNEWNET-39004. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We apologize for your inconvenience.

Hi Nayyer,


Thank you for the information. We believe we can temporarily work around this issue using multiple single threaded processes and will be testing soon, however long term we need to be able to use the library in a multi threaded environment.

Will you be posting updates here for the issue, or can I use the tracking number you provided to get status updates?

Thank you

Mike
Hi Mike,

mlarned@gmail.com:
Hi Nayyer,

Thank you for the information. We believe we can temporarily work around this issue using multiple single threaded processes and will be testing soon, however long term we need to be able to use the library in a multi threaded environment.


Sure our product team will investigate the issue and will resolve it asap, so you can use the feature in multi-threaded environment.

mlarned@gmail.com:
Hi Nayyer,

Will you be posting updates here for the issue, or can I use the tracking number you provided to get status updates?



Aspose JIRA is our internal system for tracking, customer can not access or login to it. You can only ask us for update status. However we will notify you as soon as we made some significant progress towards issue resolution.


Best Regards,

Hi Nayyer,


Wanted to check if you have any updates on this issue?

Mike

Hi Mike,


Thanks for your inquiry. I am afraid it is still not resolved. As we have recently noticed the issue, it is pending for the investigation in the queue with other issues reported earlier. We will notify you as soon as we made some significant progress towards issue resolution.


We are sorry for the inconvenience caused.


Best Regards,

Hi Tilal,


Do you have any updates on when this issue may be fixed, or if any further discoveries have been made? Thread safety is going to be an issue for us with higher traffic volumes and multiple concurrent conversions.

Thanks

Mike

Hi Mike,


Thanks for your patience.

I am afraid due to huge number of previous reported high priority issues, the issue reported in this thread is still pending for review. However your concerns have been shared with product team and they will surely consider them during its resolution.

As soon as we have some definite updates regarding its resolution, we will let you know. We are sorry for this delay and inconvenience.

Hi Nayyer,


I’m also experiencing the same issue and it’s pretty important that we’re able to do this in a threadsafe manner, has this issue been solved yet?

Phil

Hi Phil,


Thanks for contacting support.

I am afraid the earlier reported issue is still pending for review and is not yet resolved. However the product team will surely consider investigating/fixing it as per development schedule and as soon as we have some definite updates regarding its resolution, we will let you know. Please be patient and spare us little time. We are sorry for this delay and inconvenience.