msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Fix non-thread safe Flush() in RedirectConsoleWriter

Open YuliiaKovalova opened this issue 1 year ago • 3 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 https://github.com/dotnet/msbuild/pull/9983#discussion_r1563046625

YuliiaKovalova avatar Apr 16 '24 10:04 YuliiaKovalova

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

AR-May avatar Apr 16 '24 13:04 AR-May

cc: @rokonec MSBuild Server-related topic

YuliiaKovalova avatar Apr 16 '24 14:04 YuliiaKovalova

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?

rokonec avatar Apr 19 '24 22:04 rokonec