dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.

Home Page:https://docs.microsoft.com/visualstudio/msbuild/msbuild

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix non-thread safe Flush() in RedirectConsoleWriter

YuliiaKovalova opened this issue · comments

[pre-existing] It looks like the goal of this class is to expose a thread-safe StringWriter but this method is not thread-safe. Writes that happen between these two statements may be lost or corrupt the StringBuilder.

Originally posted by @ladipro in #9983 (comment)

team triage: @YuliiaKovalova what is your suggested priority for it?

cc: @rokonec MSBuild Server-related topic

Purpose of this class was to redirect all console writes from msbuild server to its client (invoker).
Since msbuild access console in serial fashion, this class was not originally written as thread safe. However, if custom code (tasks, logger and such) do call console flush directly it might interfere with logging service thread. Accessing console directly is not supported and customers shall avoid it. But if I understand it correctly, console is wired with _syncWriter = Synchronized(this); which is supposed to be thread safe wrapper.
I recommend to close this issues as "this is fine".
@MichalPavlik as an author of these particular lines, what is your take?