Skip to content

Commit 97c2d14

Browse files
authored
ensure access to logger is synchronized for async output reader (#2133)
fixes #2125
1 parent f4d99ab commit 97c2d14

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/BenchmarkDotNet/Loggers/AsyncProcessOutputReader.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,14 @@ private void ProcessOnOutputDataReceived(object sender, DataReceivedEventArgs e)
106106
if (!string.IsNullOrEmpty(e.Data))
107107
{
108108
output.Enqueue(e.Data);
109+
109110
if (logOutput)
110-
logger.WriteLine(e.Data);
111+
{
112+
lock (this) // #2125
113+
{
114+
logger.WriteLine(e.Data);
115+
}
116+
}
111117
}
112118
}
113119

@@ -116,8 +122,14 @@ private void ProcessOnErrorDataReceived(object sender, DataReceivedEventArgs e)
116122
if (!string.IsNullOrEmpty(e.Data))
117123
{
118124
error.Enqueue(e.Data);
125+
119126
if (logOutput)
120-
logger.WriteLineError(e.Data);
127+
{
128+
lock (this) // #2125
129+
{
130+
logger.WriteLineError(e.Data);
131+
}
132+
}
121133
}
122134
}
123135

0 commit comments

Comments
 (0)