msbuild
msbuild copied to clipboard
Fix non-thread safe Flush() in RedirectConsoleWriter
[pre-existing] It looks like the goal of this class is to expose a thread-safe
StringWriterbut this method is not thread-safe. Writes that happen between these two statements may be lost or corrupt theStringBuilder.
Originally posted by @ladipro in https://github.com/dotnet/msbuild/pull/9983#discussion_r1563046625
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?