Fix race condition in IpcTests#8013
Conversation
This comment has been minimized.
This comment has been minimized.
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8013) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:
Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard. Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8013) - mean (68ms) : 67, 70
master - mean (68ms) : 67, 70
section Bailout
This PR (8013) - mean (72ms) : 71, 73
master - mean (72ms) : 71, 73
section CallTarget+Inlining+NGEN
This PR (8013) - mean (1,013ms) : 955, 1071
master - mean (1,015ms) : 951, 1079
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8013) - mean (106ms) : 104, 108
master - mean (106ms) : 104, 108
section Bailout
This PR (8013) - mean (107ms) : 106, 108
master - mean (107ms) : 105, 108
section CallTarget+Inlining+NGEN
This PR (8013) - mean (731ms) : 671, 792
master - mean (725ms) : 669, 780
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8013) - mean (94ms) : 92, 96
master - mean (93ms) : 90, 96
section Bailout
This PR (8013) - mean (94ms) : 93, 95
master - mean (94ms) : 93, 95
section CallTarget+Inlining+NGEN
This PR (8013) - mean (714ms) : 674, 754
master - mean (707ms) : 676, 738
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8013) - mean (92ms) : 90, 94
master - mean (92ms) : 90, 93
section Bailout
This PR (8013) - mean (93ms) : 92, 95
master - mean (93ms) : 92, 95
section CallTarget+Inlining+NGEN
This PR (8013) - mean (632ms) : 619, 645
master - mean (631ms) : 613, 649
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8013) - mean (193ms) : 189, 198
master - mean (193ms) : 190, 197
section Bailout
This PR (8013) - mean (197ms) : 194, 199
master - mean (197ms) : 194, 199
section CallTarget+Inlining+NGEN
This PR (8013) - mean (1,118ms) : 1062, 1174
master - mean (1,114ms) : 1062, 1165
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8013) - mean (278ms) : 272, 284
master - mean (278ms) : 273, 283
section Bailout
This PR (8013) - mean (278ms) : 272, 285
master - mean (280ms) : 273, 288
section CallTarget+Inlining+NGEN
This PR (8013) - mean (928ms) : 886, 969
master - mean (923ms) : 866, 980
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8013) - mean (271ms) : 267, 275
master - mean (270ms) : 266, 274
section Bailout
This PR (8013) - mean (270ms) : 266, 274
master - mean (271ms) : 267, 274
section CallTarget+Inlining+NGEN
This PR (8013) - mean (922ms) : 879, 966
master - mean (918ms) : 872, 964
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8013) - mean (269ms) : 265, 273
master - mean (270ms) : 264, 277
section Bailout
This PR (8013) - mean (270ms) : 266, 274
master - mean (269ms) : 266, 271
section CallTarget+Inlining+NGEN
This PR (8013) - mean (826ms) : 807, 846
master - mean (822ms) : 803, 841
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BenchmarksBenchmark execution time: 2026-01-07 11:13:12 Comparing candidate commit 0e4f488 in PR branch Found 12 performance improvements and 7 performance regressions! Performance is the same for 158 metrics, 9 unstable metrics. scenario:Benchmarks.Trace.ActivityBenchmark.StartStopWithChild netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleMoreComplexBody netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs net6.0
scenario:Benchmarks.Trace.Asm.AppSecEncoderBenchmark.EncodeLegacyArgs netcoreapp3.1
scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack netcoreapp3.1
scenario:Benchmarks.Trace.AspNetCoreBenchmark.SendRequest net6.0
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0
scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSlice net6.0
scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0
scenario:Benchmarks.Trace.DbCommandBenchmark.ExecuteNonQuery net472
scenario:Benchmarks.Trace.Iast.StringAspectsBenchmark.StringConcatBenchmark net6.0
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0
scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1
scenario:Benchmarks.Trace.TraceAnnotationsBenchmark.RunOnMethodBegin net6.0
|
Summary of changes
Fixed race condition in IpcClientTest that caused intermittent test failures where finalValue.ClientValue was 19 instead of 20.
Reason for change
The test was failing intermittently in CI with:
Expected finalValue.ClientValue to be 20, but found 19 (difference of -1).Root cause: Race condition where TaskCompletionSource.TrySetResult(true) signaled completion before Interlocked.Exchange(ref finalValue, value) updated finalValue with the final message. The main test thread would wake up and read finalValue before it contained the final state.
Starting with message (19, 19):
server -> value.ServerValue++; // Server: (19,19) → (20,19)
server -> server.TrySendMessage(value) // Sends (20,19) to client
client -> value.ClientValue++; // Client: (20,19) → (20,20)
client -> Interlocked.Exchange(ref finalValue, value); // ✅ Stores (20,20)
client -> clientTaskCompletion.TrySetResult(true); // ✅ Signals client done
server -> Interlocked.Exchange(ref finalValue, value); // ❌ Stores (20,19) - OVERWRITES!
server -> serverTaskCompletion.TrySetResult(true); // ✅ Signals server done
Implementation details
Moved Interlocked.Exchange(ref finalValue, value) outside the if (value < maxNumber) conditional blocks in both server and client callbacks (IpcTests.cs:42 and IpcTests.cs:62). Now every received message updates finalValue, not just messages with values < 20.
This ensures that when TaskCompletionSource signals completion, finalValue is guaranteed to contain the most recent message state.
Test coverage
Other details