Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding MemoryContentProvider is not thread-safe #32

Open
wsitko opened this issue Mar 4, 2014 · 2 comments
Open

Adding MemoryContentProvider is not thread-safe #32

wsitko opened this issue Mar 4, 2014 · 2 comments

Comments

@wsitko
Copy link

wsitko commented Mar 4, 2014

The piece of code causing the issue at RazorMachine.cs

        protected MemoryContentProvider MemoryContentProvider {
            get {
                var provider = Context.TemplateFactory.ContentManager.TryGetContentProvider<MemoryContentProvider>();
                if (provider == null)
                    Context.TemplateFactory.ContentManager.AddContentProvider(provider = new MemoryContentProvider());
                return provider;
            }
        }

When two threads reach the getter at the same time (using one RazorMachine instance) it is possible that both of them add new MemoryContentProvider to the context and each next call to Context.TemplateFactory.ContentManager.TryGetContentProvider() will throw an exception (SingleOrDefault at CompositeContentProvider.TryGetContentProvider(Type type)).

This situation is possible only when calling the MemoryContentProvider getter first time, but this can leave the RazorMachine object in unusable state.

@RubinhoProgressive
Copy link

Is there already a solution for this problem?

@wsitko
Copy link
Author

wsitko commented Oct 12, 2014

I'm not using the latest version, but I don't think so.
You can add lock statement in the source code above and build the library on your own, but I've done this on higher level to make the change quicker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants