Skip to content

Thread safety of RazorEngine.ErrorMessage #40

@v1k7-992

Description

@v1k7-992

Hi, if we have an application that is using any derived type from RazorTemplateBase, and using the application wrapper as described in the documentation (link to doc), for instance, if there would be a case where two threads try generating output based on a template, with different model data, if one thread for instance fails, and the other passes, that might result in a case where the ErrorMessage string would potentially be overwritten to null for the thread that failed, or it would have been overwritten with incorrect error message in the thread that succeeded in making a valid response? And then when accessing ErrorMessage we might not be able to access the reason why template generation failed.

This is all theoretical and I haven't observed such a a situation when using this library so far.

What would you suggest to be able to avoid such thread safety issues that might occur?
I am thinking of two things:

  • Either using all the HostContainers in a Object pool
  • Or maybe wrapping ErrorMessage in a lock statement?

In any case, thanks for any feedback provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions