VenusInterns / BlogTemplate

MIT License
208 stars 38 forks source link

The singleton 'Blog' service is not thread-safe #47

Closed Eilon closed 7 years ago

Eilon commented 7 years ago

In Startup.cs a singleton 'Blog' service is registered:

https://github.com/VenusInterns/BlogTemplate/blob/master/BlogTemplate/Startup.cs#L48

But the implementation of the Blog class is clearly not thread-safe for multiple writers:

https://github.com/VenusInterns/BlogTemplate/blob/master/BlogTemplate/Models/Blog.cs#L11-L13

That is, if two threads (e.g. two requests) both call Blog.Comments.Add(...) at the same time, something "bad" will happen.

For example, see this code here: https://github.com/VenusInterns/BlogTemplate/blob/master/BlogTemplate/Pages/New.cshtml.cs#L70

jimmylewis commented 7 years ago

Fixed by #59