Closed Eilon closed 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.
Blog.Comments.Add(...)
For example, see this code here: https://github.com/VenusInterns/BlogTemplate/blob/master/BlogTemplate/Pages/New.cshtml.cs#L70
Fixed by #59
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